靜態成員函數和(CPP與C結構體的區別)
阿新 • • 發佈:2019-05-02
out 寫法 結構體 std get unsigned name 靜態成員函數 但是
#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
靜態成員函數和(CPP與C結構體的區別)