c ++基类中无法访问的构造函数

时间:2016-06-30 09:01:31

标签: c++ inheritance constructor

    class Timp {

    // constructori
    Timp() {
        this->timp_intre_taste = 0;
        this->timp_tasta = 0;
    }

    Timp(int t1, int t2) {
        this->timp_intre_taste = t1;
        this->timp_tasta = t2;
    }
    // getteri and setteri 

    int getTimpIntreTaste(){
        return timp_intre_taste;}
    void setTimpIntreTaste(int timpIntreTaste){
        timp_intre_taste = timpIntreTaste;}

    int getTimpTasta()
    {
        return timp_tasta;
    }
    void setTimpTasta(int timpTasta)
    {
        timp_tasta = timpTasta;
    }

protected:
    int timp_intre_taste;
    int timp_tasta;

};

class Sesiune : public Timp 
{

    int id_utilizator;
    int nr_click_stanga;
    int nr_click_dreapta;

public:
    Sesiune():Timp(0,0)
    {
        this->id_utilizator = 0;
        this->nr_click_dreapta = 0;
        this->nr_click_stanga = 0;
    }

我有这些错误:

  

严重级代码说明项目文件行列抑制状态   错误(活动)" Timp :: Timp(int t1,int t2)" (在第17行宣布)是   无法访问Project3.0 d:\ salv \ facultate \ visualstudio \ Project3.0 \ Project3.0 \ Source.cpp 51 16

1 个答案:

答案 0 :(得分:0)

错误说明发生了什么。类的默认属性是“private”,这意味着只有这个类才能访问它。没有其他类可以访问它。您必须更改为公共(每个人都有访问权限)或受保护(只有此类和派生类可以访问)