小编Her*_*ron的帖子

C++ Friend构造函数

我有两个班级:Point只住在Space

class Point
{
private:
    Point(const Space &space, int x=0, int y=0, int z=0);
    int x, y, z;
    const Space & m_space;
};
Run Code Online (Sandbox Code Playgroud)

构造函数是故意私有的,我不希望它被直接调用.我想用这种方式创建点数

Space mySpace;
Point myPoint = mySpace.Point(5,7,3);
Run Code Online (Sandbox Code Playgroud)

有没有办法这样做?谢谢.

c++

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1