`

c++ 入门

    博客分类:
  • c++
阅读更多
1 创建类,并在定义的类中定义函数及必要的成员变量
2.要去实现类中所创建的类及成员变量
3.在入口中去做具体的调用。
so simple!
eg:

#include <iostream>
using namespace std;


class one{
public:
void setOne(int c,int d);
int getC();
int getD();
public:
int a,b;

};

int f = 2;
int g = 3;

void one::setOne(int c, int d){
a = c;
b = d;
}
int one::getC(){
return a;
}
int one::getD(){
return b;
}
one o;
void main(){
o.a = f;
o.setOne(f,g);
cout<<o.getC()<<endl;
cout<<o.getD()<<endl;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics