美文网首页
53 - protected Members

53 - protected Members

作者: 社交帐号直接注册 | 来源:发表于2018-01-05 17:20 被阅读0次
    1.main.cpp
    #include <iostream>
    #include "Mother.h"
    #include "Gaughter.h"
    using namespace std;
    
    int main()
    {
        Gaughter tinaa;
        tinaa.doSomething();
        return 0;
    }
    2.Mother.h
    #ifndef MOTHER_H
    #define MOTHER_H
    
    class Mother
    {
    public:
        int publicv;
    protected:
        int protectedv;
    private:
        int privatev;
    };
    
    #endif // MOTHER_H
    3.Mother.cpp
    #include <iostream>
    #include "Mother.h"
    #include "Gaughter.h"
    using namespace std;
    4.Gaughter.h
    #ifndef GAUGHTER_H
    #define GAUGHTER_H
    
    class Gaughter:public Mother
    {
    public:
        void doSomething();
    };
    
    #endif // GAUGHTER_H
    5.Mother.h
    #include <iostream>
    #include "Mother.h"
    #include "Gaughter.h"
    using namespace std;
    
    void Gaughter::doSomething()
    {
        publicv = 1;
        protectedv = 2;
    
    }

    相关文章

      网友评论

          本文标题:53 - protected Members

          本文链接:https://www.haomeiwen.com/subject/ojjsnxtx.html