C++ 错误:构造函数是私有的
小问题: 下面是课堂:C++ 错误:构造函数是私有的,c++,C++,小问题: 下面是课堂: class Author { Author(const std::string& name, const std::string& email, Gender gender); Author& setName(const std::string& name); private: std::string a_name; std::string a_email; int a_gender; } 我
class Author
{
Author(const std::string& name, const std::string& email, Gender gender);
Author& setName(const std::string& name);
private:
std::string a_name;
std::string a_email;
int a_gender;
}
我不知道为什么,他写下了下一个错误:
错误:“Author::Author(常量字符串&,常量字符串&,性别)”是私有的|
但它是防御构造师,所以女贞对他来说是什么,所以他不能得到ACSS
坦克 在
类中的访问权限默认为私有:
,而不是公共:
这:
应该是:
class Author
{
public:
Author(const std::string& name, const std::string& email, Gender gender);
Author& setName(const std::string& name);
公开:在构造函数前面,或者用struct
替换class
。并添加一个尾随代码>。
class Author
{
public:
Author(const std::string& name, const std::string& email, Gender gender);
Author& setName(const std::string& name);