I have an issue with linker errors attempting to overload << for cout, which I seemed to be going back and forth between Stackoverflow and related websites, and adjusting the code based on the other threads, with no success. Please note that I am very new to overloading, and just did many of the Math operator overloading in this program, which also took a lot of back and forward, but I think is now working...
Anyway, I was attempting to place the definition inside the class in the header file as follows:
std::ostream& operator<<(std::ostream&, const Vector2&);
And the definition in the CPP file:
std::ostream& operator<<(std::ostream& os, const Vector2& VInput)
{
std::string TempString = "{ " + std::to_string(VInput.x) + ", " + std::to_string(VInput.y) + " }";
os << TempString;
return os;
}
However I was getting errors about not being able to find the definition. I then read to move the declaration out of the class, so the definition as it is above, is now in the header file, but not encapsulated inside the class brackets.
This stopped the undefined error, but now I get a LNK2019 error telling me that there is an unresolved external.
I then found another person saying to put the definition with the the declaration as one, but when I do that I get a LNK2005 error telling me the function has been defined multiple times, I believed as the Include for this header is in several locations in the project.
I am guessing I am doing something very simple, or else what I am trying to do is just bad, but could someone let me know based on the code above and where I am placing it what could be causing these errors?