Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 运算符重载C++;;<;的参数太多&书信电报;活动_C++_Operator Overloading - Fatal编程技术网

C++ 运算符重载C++;;<;的参数太多&书信电报;活动

C++ 运算符重载C++;;<;的参数太多&书信电报;活动,c++,operator-overloading,C++,Operator Overloading,我在下面有一些代码,它会记录一些名字和年龄,并用它们做一些事情。最终它会把它们打印出来。我需要用一个全局操作符更改我的print()函数您正在重载将操作符重载函数声明为好友 friend ostream& operator<<(ostream& out, int x) { out << names[x] << " " << ages[x] <<endl; return out; } fr

我在下面有一些代码,它会记录一些名字和年龄,并用它们做一些事情。最终它会把它们打印出来。我需要用一个全局
操作符更改我的
print()
函数您正在重载
将操作符重载函数声明为好友

friend ostream& operator<<(ostream& out, int x)
{
        out << names[x] << " " << ages[x] <<endl;
        return out;
}

friend ostream&operator如果该操作符是
自由函数
(即不是类的成员函数),则它将无法访问类的私有成员。来自java等语言的
toString
方法功能强大,因为它可以访问所有内容以获得纯文本输出。
friend ostream& operator<<(ostream& out, int x){
     out << names[x] << " " << ages[x] <<endl;
     return out;
}
friend ostream& operator<<(ostream& out, int x)
{
        out << names[x] << " " << ages[x] <<endl;
        return out;
}