首页 > 其他 > 详细

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

时间:2019-05-02 16:53:00      阅读:161      评论:0      收藏:0      [点我收藏+]
#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结构体的区别)

原文:https://www.cnblogs.com/overlows/p/10802609.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!