0

So I am making a my own copy of the Vector STL class. I know it is not practical this is just what I'm doing. I'm using visual studio. Here is my code...

myVector.h

namespace  CS52 {
    class  Vector {
    public:
        friend std::ostream& operator<<(std::ostream&, Vector &);
    };
}

myVector.cpp

#include "myVector.h"
#include <fstream>

std::ostream& CS52::Vector::operator<<(std::ostream&, CS52::Vector &)
{
    // TODO: insert return statement here
}

The error I get is Class "CS52::Vector" has no member "operator<<" Thanks

MaxAttax
  • 67
  • 6

1 Answers1

0

You only declared this operator to be a friend of the class.

This should instead be something like:

namespace  CS52 {
    class  Vector {
    public:
        friend std::ostream& operator<<(std::ostream&, Vector &);
    };
    std::ostream& operator<<(std::ostream& stream, Vector &v);
}

And then:

namespace  CS52 {
    std::ostream& operator<<(std::ostream& stream, Vector &v)
    {
       return stream;
    }
}
Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62