I'm quite new to c++ and my current problem is to output a struct using an overloaded operator. I've tried my best, but apparently it is not enough. Anyone knows why my compiler keeps pushing out this mistake: \main.cpp|16|error: no match for 'operator<<' (operand types are 'std::basic_ostream' and 'const Eyecolor')|
This is the corresponding code:
#include <iostream>
#include <string>
using namespace std;
enum class Eyecolor {blue, brown, green};
struct PStruct {
string surname;
Eyecolor eyecolor;
double height;
bool gender;
friend std::ostream& operator<<(std::ostream& os, const PStruct& ps);
};
std::ostream& operator<<(std::ostream& os, const PStruct& ps)
{
os << ps.surname << '/' << ps.height << '/' << ps.gender << '/' << ps.eyecolor; //line 16
return os;
}
void print(){
cout << os;
}
int main()
{
return 0;
}
I'm pretty sure i defined the operator<< one line prior to that.
Anyway thanks for the answers in advance