恩,你理解错误
公有和私有都可以是数据或者函数
c = a +b, 不可以这么用的,需要放在函数里面
#include"iostream"
using namespace std;
class A///类型名别跟变量名弄一样的
{
private:///如果不写,默认为private
int a,b,c;
public:
A()/////构造函数,自动调用的, 赋值都放在函数里面
{
a = 2;
b = 3;
c=a+b;
}
void Display()
{
cout << a << '\t' << b << '\t' << c << endl;
}
};////////////////分号是必须的
int main()
{
A test;
test.Display();
system("pause");
return 0;////尽量写上返回值
}