class LongInt
{

    friend ostream & operator <<(ostream & os, const LongInt & integer);

...
}

ostream & operator <<(ostream & os, LontInt & container)
{
    os << container.number.size(); //error here


    return os;
}

error: 'std::vector LongInt::number' is private vector number; ^

I don't understand why I can't access the variable, does it have to do something with the fact that the member variable is a vector?

有帮助吗?

解决方案

Because it's not a friend of that function: the signature is different. Note const modifier of the second parameter.

其他提示

I think you are missing a const in the declaration before LongInt, which makes the signatures different, and the compiler doesn't think it's the same function that you declared as friend.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top