i have this code snippet
#include <iostream>
using namespace std;
class Polygon
{
public:
int publicmemberPolygon;
private:
int privatememberPolygon;
protected:
int protectedmemberPolygon;
};
class Square : public Polygon
{
public:
int Getter();
};
int Square::Getter()
{
return privatememberPolygon;
}
int main()
{
}
problem is, why is privatememberPolygon is inaccesbile? isnt it, when you have a dervied class, all of its members/functions are copied? thanks
No, when you derive publicly from a base class, only its
publicandprotectedmembers are accessible for the derived class. You can also read this FAQ.See this example: