unresolved external symbol

Hi I have this code which works perfectly

1
2
3
4
5
6
7
8
9
ostream& operator << (ostream& os,polynomial a) {
	for (size_t i=0;i<a.numer.size();i++) {
		if (a.numer.at(i).get_coeff()>=0 && i!=0) {
			os<<"+";
		}
		//os<<a.numer.at(i);
	}
	return os;
}


But once I remove the commented line to get this

1
2
3
4
5
6
7
8
9
ostream& operator << (ostream& os,polynomial a) {
	for (size_t i=0;i<a.numer.size();i++) {
		if (a.numer.at(i).get_coeff()>=0 && i!=0) {
			os<<"+";
		}
		os<<a.numer.at(i);
	}
	return os;
}


I get a linking error like this


error LNK2001: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,struct monomial)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@Umonomial@@@Z)


I searched about this on google and I saw some similar problems but the solution was something with a template but I don't really use templates here (except for my vectors) So does someone know what's going on ?

Edit: numer is defined like this:
 
vector <monomial> numer;
Last edited on
Did you include the necessary headers?
You did not define operator << for struct monomial.
Yes I did both
And did you add all your files to the project?
I have put my polynomial class in the same file as my monomial class and I only use an other file a few times for just one function but that's totally somewhere else
Umm well Vlad was right... my monomial didn't have it's << operator anymore..
I am really sure I wrote it tough I guess I have removed it by accident -.-
Expect unexpected and simple mistakes to happen all the time. :)
Topic archived. No new replies allowed.