In main.cpp
:
#include <iostream>
#include "MyType.h"
int main(int argc, const char * argv[]) {
MyType myobject = MyType();
std::cout << myobject; //error here
return 0;
}
in MyType.h
:
#include <ostream>
class MyType {
public:
MyType();
std::ostream& operator<<(std::ostream &os);
};
in MyType.cpp
:
#include "MyType.h"
#include <iostream>
MyType::MyType() {
}
std::ostream& MyType::operator<<(std::ostream &os){
return os;
}
I am trying to overload << for a custom type. When I do, I get this error: /main.cpp:14:15: Invalid operands to binary expression ('ostream' (aka 'basic_ostream<char>') and 'MyType')
What am I doing wrong here?