0

Still cannot get this one to work. Please help!

template <typename T>
class Container{
public:
    ...

    friend ostream& operator<<(ostream& ostr, const Container<T>& C)
    {
        for(size_t i=0; i!= data.size(); i++) // ERROR
            ostr<<data[i]<<" "; 
        return ostr;
    }

private:
    vector<T> data;
};
Oliver Charlesworth
  • 260,367
  • 30
  • 546
  • 667
user2696565
  • 578
  • 7
  • 17

1 Answers1

4

data is a member of C and should therefore be accessed as C.data (remember that your operator<< is a free function and not a member of Container):

    for(size_t i = 0; i != C.data.size(); ++i)
        ostr << C.data[i] << " "; 
Community
  • 1
  • 1
NPE
  • 464,258
  • 100
  • 912
  • 987