我的问题是很容易通过这个例子来说明:默认赋值运算符访问基类的私有成员
class Vector3
{
float _x;
float _y;
float _z;
public :
/// constructors and stuff
};
class Point : public Vector3
{
// some BS
Point(float _x):Vector3(float _x)
{}
};
main()
{
Point aPoint(3);
Point anotherPoint(4);
// WHY DOES THIS WORK and copy _x,_y & _z properly
aPoint = anotherPoint;
}
基本上,我茫然地理解为什么=
为派生类可以复制_x
,_y
和_z
,即使它们不应该访问它们,因为它们是私有的。
“It”should not have access?谁不应该访问? – jogojapan
“默认=为派生类” – angryInsomniac
你知道这不是有效的C++,对吧? –