我的問題是很容易通過這個例子來說明:默認賦值運算符訪問基類的私有成員
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++,對吧? –