I’m writing a program that creates a complex number class and I am getting these two errors when i try to test my overloaded operator >>. Here are the errors:
error LNK2028: unresolved token
(0A0002BD) “class
std::basic_istream > & __cdecl
operator>>(class
std::basic_istream > &,class
Complex const &)”
(??5@$$FYAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@ABVComplex@@@Z)
referenced in function “int __cdecl
main(void)” (?main@@$$HYAHXZ)error LNK2019: unresolved external
symbol “class
std::basic_istream > & __cdecl
operator>>(class
std::basic_istream > &,class
Complex const &)”
(??5@$$FYAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@ABVComplex@@@Z)
referenced in function “int __cdecl
main(void)” (?main@@$$HYAHXZ)
Here is my overload function:
istream& operator >> (istream& in, Complex& a){
double real, imaginary;
in >> real >> imaginary;
a.setReal(real);
a.setImaginary(imaginary);
return in;
}
Also it says its coming from my mainComplex.obj, mainComplex is a cpp file that has the main function i use to test the program.
int main(){
Complex num;
cout << "Enter Complex number: ";
cin >> num;
return 0;
}
The compiler, when processing
mainhas found that the best overload for the expressioncin >> num;isstd::basic_istream<...>& operator>>( std::basic_istream<...>&, const Complex& ), note theconstin the second argument.This probably indicates that you have declared the operator as:
But then implemented: