C++ 友元函数无法访问类C++;
我正在尝试重载操作符“您的C++ 友元函数无法访问类C++;,c++,class,friend,C++,Class,Friend,我正在尝试重载操作符“您的操作符您的操作符,因为您没有将这些成员“限定”到实例中。您需要编写 ostream & operator<<(ostream & out, callClass &Org) { if (Org.isEmpty() == 1) // ^^^^^ ostream&operator,因为您没有将这些成员“限定”为实例。您需要编写 ostream & operator<<(ostream & ou
操作符您的操作符,因为您没有将这些成员“限定”到实例中。您需要编写
ostream & operator<<(ostream & out, callClass &Org)
{
if (Org.isEmpty() == 1)
// ^^^^^
ostream&operator,因为您没有将这些成员“限定”为实例。您需要编写
ostream & operator<<(ostream & out, callClass &Org)
{
if (Org.isEmpty() == 1)
// ^^^^^
ostream和操作符
为什么friend函数不能访问isEmpty()、计数和调用_DB[]
因为您不理解“access”的含义。这并不意味着friend函数成为类的一个方法,所以您不能在尝试使用时隐式使用此
,您应该使用Org
参数:
out << setw(10) << Org.call_DB[i].firstname << " ";
out
为什么friend函数不能访问isEmpty()、计数和调用_DB[]
因为您不理解“access”的含义。这并不意味着friend函数成为类的一个方法,所以您不能在尝试使用时隐式使用此
,您应该使用Org
参数:
out << setw(10) << Org.call_DB[i].firstname << " ";
out您的好友函数不是成员函数,因此没有可用的“this”。您的操作员代码应该如下所示:
ostream & operator<<(ostream & out, callClass &Org)
{
for (int i = 0; i < count; i++)
{
out << Org.call_DB[i] << endl;
}
}
}
ostream&operator您的好友函数不是成员函数,因此没有可用的“this”。您的运算符代码应如下所示:
ostream & operator<<(ostream & out, callClass &Org)
{
for (int i = 0; i < count; i++)
{
out << Org.call_DB[i] << endl;
}
}
}
ostream&operator他们将操作符作为类的一部分(callClass::operator他们需要在Org
上调用。这不是问题,但不要使用std::endl
,除非你需要额外的东西。'\n'
结束一行。或者将操作符作为类的一部分(callClass::Operator需要在Org
上调用它们。这不是问题所在,但不要使用std::endl
,除非您需要额外的东西。'\n'
结束一行。