C++报错无法访问Private
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2248 “main::Person::~Person”: 无法访问 private 成员(在“main::Person”类中声明)
#include<iostream>
#include<ctime>
int main()
{
using namespace std;
class Person
{
//Person()
//{
//cout << "构造函数调用"<<endl;
//}
Person(int age)
{
cout << "有参构造函数调用" << endl;
}
Person(const Person &p1)
{
cout << "拷贝构造函数调用" << endl;
}
~Person() {
cout << "析构函数被调用" << endl;
}
};
Person p1(18);
Person p2 = p1;
return 0;
}
解决方案:添加public关键字即可
原文地址:https://blog.csdn.net/quaer/article/details/140215386
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!