Why protected superclass member cannot be accessed in a subclass function when passed as an argument

Posted by KNoodles on Stack Overflow See other posts from Stack Overflow or by KNoodles
Published on 2010-04-01T03:18:22Z Indexed on 2010/04/01 3:23 UTC
Read the original article Hit count: 347

Filed under:
|
|
|

I get a compile error, which I'm slightly confused about. This is on VS2003.

error C2248: 'A::y' : cannot access protected member declared in class 'A'

class A
{
public:
  A() : x(0), y(0) {}
protected:
  int x;
  int y;
};

class B : public A
{
public:
  B() : A(), z(0) {}
  B(const A& item) : A(), z(1) { x = item.y;}
private:
  int z;
};

The problem is with x = item.y;

The access is specified as protected. Why doesn't the constructor of class B have access to A::y?

© Stack Overflow or respective owner

Related posts about c++

Related posts about superclass