-1
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?

OnTheFly
  • 2,059
  • 5
  • 26
  • 61

2 Answers2

3

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

Denis Itskovich
  • 4,383
  • 3
  • 32
  • 53
  • ah, weird, it should have given me a different error msg. – OnTheFly Feb 28 '14 at 04:17
  • @OnTheFly No, it shouldn't. This because `friend` specifier does not obligate you to have function with specified signature. If you are trying to use private members in outer class/global function it will check whether this class/global function is in the friend list. – Denis Itskovich Feb 28 '14 at 04:19
1

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.

DS.
  • 22,632
  • 6
  • 47
  • 54