静态成员函数和(CPP与C结构体的区别)

mac2022-06-30  25

#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

转载于:https://www.cnblogs.com/overlows/p/10802609.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)