我很难过,我现在正在学习 C++ 课程,这是我遇到的问题,我必须声明和定义构造函数,我不知道我在做什么错我尝试但无法得到结果请帮助
#include <iostream>
using namespace std;
class exercise
{
public:
//declaration: constructor of class exercise
int public_var;
int get_private_var();
private:
int private_var;
};
//definition: constructor of class exercise
int exercise::get_private_var()
{
return private_var;
}
int main()
{
exercise object(2,3);
int pub_var = object.public_var;
int pri_var = object.get_private_var();
cout << pub_var <<' '<<pri_var<<endl;
return 0;
}