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
  • 267,707
  • 33
  • 569
  • 680
user2696565
  • 587
  • 1
  • 8
  • 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
  • 486,780
  • 108
  • 951
  • 1,012