I'm trying to overload the << operator for a class (easy, right? :P)
However, I get the linker error: undefined reference to `operator<<(std::ostream&, particle const&)'
Which my understanding means the compiler can't find the implementation for operator<<.
I'm not sure whats going on here, since I've already implemented the function. Previously when I've overloaded << for a class I'd define it as a non-friend and use x.getvariable(), but I can't figure out why this won't work.
//Inside particle.h
#include <sstream>
class particle {
private:
double Xcomp;
double Ycomp;
double Zcomp;
public:
...
friend std::ostream& operator<<(std::ostream& outs, const particle& x);
};
//Inside particle.cpp
#include <sstream>
#include "particle.h"
using namespace std;
ostream& operator<<(ostream& outs, const particle& x){
outs << Xcomp << " "
<< Ycomp << " "
<< Zcomp << " ";
return(outs);
}
//in main
#include "particle.h"
void main() {
particle x;
cout << x;
}