[英]Trouble accessing private members with friend function in c++ operator<< overload
So I'm trying to overload the << operator. 所以我想重载<<操作符。 From all the sources I can see, the syntax is correct, but eclipse doesn't like it.
从我可以看到的所有来源看,语法都是正确的,但是eclipse不喜欢它。
I'm getting a couple errors: Polynomial::PrivateStruct* Polynomial::head is private 我遇到了几个错误: 多项式:: PrivateStruct *多项式:: head是私有的
And: struct Polynomial::PrivateStruct is private. 并且: struct Polynomial :: PrivateStruct是私有的。
I want to keep this struct private as to hide implementation details. 我想将此结构保持私有状态以隐藏实现细节。
std::ostream& operator<<(std::ostream& outputStream, Polynomial& rhs)
{
Polynomial::PrivateStruct *p = rhs.head;
//implementation details
return outputStream;
}
and the declaration: 和声明:
friend std::ostream& operator<<(std::ostream& outputStream, const Polynomial& rhs);
The declaration and the definition don't match - one takes a reference to const
, the other to non-const. 声明和定义不匹配-一个引用
const
,另一个引用非const。 Match them and you're good to go. 匹配它们,您就可以开始了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.