试图将重载的 cout 函数调用放入另一个 cout 重载的函数中

问题描述

我的代码中有两个对象。一个在另一个中使用。我正在尝试编写一个重载的 cout 函数,它将打印每个类中的项目。尝试运行我的程序时出现错误

error: invalid use of non-static data member 'Glip::brain'
         outs << brain;
                 ^~~~~
friend ostream &operator<<(ostream &outs,const Glip &glip){
    outs << std::right << setw(10) << glip.name << "\n";
            outs << "----------------- \n";
            outs << "Height: " << right << setw(1) << glip.height << "\n";
            outs << "Weight: " << setw(1) << glip.weight << "\n";
            outs << "Color: " << setw(1) << glip.color << "\n";
    if(glip.horn == true) {
        outs << left << setw(4) << "Horn";
    }
    else
        outs << setw(4) << "No Horn";

    outs << brain;

    return outs;
}

我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)