我有两个类:Point
,即只生活在Space
C++朋友构造
class Point
{
private:
Point(const Space &space, int x=0, int y=0, int z=0);
int x, y, z;
const Space & m_space;
};
构造函数是故意私人的,我不希望它被直接调用。 我想创建这样的点
Space mySpace;
Point myPoint = mySpace.Point(5,7,3);
有没有什么办法可以这样做?谢谢。
研究['friend'](http://en.cppreference.com/w/cpp/language/friend)类和函数。 –
*构造函数是故意隐私* ...为什么? –