C ++:无法读取数组中的内容

我在类中建立了一个数组,并在其中存储了一些变量,但是当我尝试在数组中读取这些变量时,它总是打印出一些空白的东西。

这是我的头文件:

model = smf.ols('AAPL ~ + SPY',data=df)
result = model.fit(cov_type = 'HAC',cov_kwds = {'maxlags':5})
print(result.summary2())

这是我的cpp文件

class animal{
private:
    string name;
    int age;
    int state;
    double income;
    string health;

};

class seaLion: public animal{
private:
    string name;
    int state;
    int age_sl;
    string health;
    seaLion *c;

public:
    seaLion();
    seaLion(string name,int age);
    ~seaLion();
    seaLion(const seaLion& copy);
    seaLion &operator = (const seaLion& copy);
    void new_sl(seaLion *c,int num);
    void cal_income(seaLion *,double);
};
xaut2008 回答:C ++:无法读取数组中的内容

如果您对“ C ++继承”进行了某些搜索,则可以找到this page例如:

  

访问控制和继承

     

派生类可以访问其基类的所有非私有成员。因此,派生类的成员函数不应该访问的基类成员应在基类中声明为私有。

     

我们可以按照以下方式根据“谁可以访问它们”来总结不同的访问类型

     

访问权限:-公共-受保护-私有

     

同一个班级-是-是-是

     

派生类-是-是-否

     

外部课程-是-否-否

因此Sealion无法访问Animal中的变量。但是,您可以通过在Sealion中声明相同名称的局部变量来隐藏它。 如果要制作一个Animal* sl = new Sealion();之类的对象并写入sl->name,那么您正在写入name中的Animal。而且,如果您尝试在成员函数{{1}中访问name,那么您正在访问Sealion中的name ...这是不同的对象!

我建议您开始学习基本的C ++教程或书籍,因为您的代码存在一些严重问题。这就是我要在C ++中做到的方式

Sealion
本文链接:https://www.f2er.com/3127757.html

大家都在问