64,682
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
class CCar
{
//成员数据
private:
int number;
int color;
int v;
//共享数据
public:
int add()//void改为int
{
v+=5;
return v;//添加返回值
}
void setv(int a)
{
v=a;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
CCar CarA;
CarA.setv(1);//为v设置初值
cout<< CarA.add();
cout<<endl;
return 0;
}
#include<iostream>
using namespace std;
class CCar
{
//成员数据
private:
int number;
int color;
int v= 0; // 初始化
//共享数据
public:
int add() // 要有返回值 才能打印!!!
{
return v += 5;
}
void setv( int a )
{
v = a;
}
};
void main()
{
CCar CarA ;
cout << CarA.add();
cout << endl;
}