Pregunta

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?

¿Fue útil?

Solución

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

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top