The problem is: the overloaded (+) works fine IF the previous code is in the same cpp file that contains the main() function
but when I put that code in any other file (eg. 1.cpp) and write the following:
1 2 3 4 5 6 7 8 9 10 11 12 13
// MyTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "1.cpp"
int main()
{
fPoint p1(1,3) , p2(3,4);
fPoint p3=p1+p2;
return 0;
}
two errors pop up!
1 2
Error 1 error LNK2005: "class fPoint __cdecl operator+(class fPoint,class fPoint)" (??H@YA?AVfPoint@@V0@0@Z) already defined in MyTest.obj 1.obj MyTest
Error 2 fatal error LNK1169: one or more multiply defined symbols found C:\CppPros\MyTest\Debug\MyTest.exe 1 MyTest
(I'm using Microsoft Visual Studio 2008 professional edition)