I am working on a C++ assignment for class that wants me to overload the ">>" operator. I am encountering errors linking in both Visual Studio 2005 and Xcode 3.2.2. The C++ code is separated into a few files. The prototypes are stored in overload.h, the implementations are stored in overload.cpp, and main()
is in overloadtester.cpp (although I have not been able to put anything related to this new overloaded operator in main yet because of the error. below is the code I added before I started getting the errors (listed below)
// overload.h
// Class Name OverloadClass
#ifndef _OverloadClass_H
#define _OverloadClass_H
#include < string >
using namespace std ;
class OverloadClass
{
public:
// Constructors and methods
private:
x_;
y_;
};
istream& operator>> (istream& in, OverloadClass &p);
#endif
// overload.cpp
#include < iostream >
#include < string >
#include < sstream >
#include < istream >
extern "C"
{
#include "DUPoint.h"
}
using namespace std ;
void OverloadClass::input()
{
char leftParen;
char comma ;
cin >> leftParen >> x_ >> comma;
char rightParen;
cin >> y_ >> rightParen;
}
// Constructor and method implementations
istream& operator>> (istream& in, OverloadClass &p)
{
p.input();
return in;
}
The error I have been getting in Xcode is:
Link ./OverloadDirectory Undefined symbols: "operator>>(std:basic_istream >&, OverloadClass&)" referenced from: _main in overloadtester.o ld: symbol(s) not found collect2: ld returned 1 exit status
I dont have access to the computer with VS at this very moment hopefully when I do I can post the error I am getting from running the code on that IDE.
Edited in response to @Mark's request for more details
Edited in response to @sbi's request for more info on input()