C++问题请帮忙!!!

来源:百度知道 编辑:UC知道 时间:2024/09/23 20:11:37
class st[ public: st()[] prive: int a; st(int);] ; 当在main()中定义st k;时,那私有中的构造函数会怎样?会被用吗? 再问一下把构造函数放在私有有什么用?

class st
{
public:
st(){}
private:
int a;
st(int);
};

st k;
调用不带参数的构造函数。
当然不会调用私有的构造函数。
私有构造函数的作用,基本上就是阻止类似 st k(1);的构造方式。
而由factory, singleton等设计模式来构造。

同意楼上的回答。
不过,麻烦楼主写正规一点,即使不换行,也把符号写对。