#include <iostream>
using namespace std.;
//这种写法只是CPP中的struct的用法,可是在C中仍是不支持的。
//C中的结构体不支持写方法的。
struct A{
private:
int a;
public:
void setA(int A){a=A;}
int getA()const{return a;}
};
struct B : A{
};
//验证类的静态成员函数性质
class AA{
public:
static void aa();
private:
int t;
};
void AA::aa(){
cout<<"静态成员函数"<<endl;
}
int main(int argc, const char * argv[]) {
//验证类的静态成员函数性质。
AA bb;
bb.aa();
AA::aa();
unsigned a=9;
//验证CPP结构体与C结构体
B b;
b.setA(2);
cout<<b.getA()<<endl;
return 0;
}
运行结果
静态成员函数
静态成员函数
2
Program ended with exit code: 0