0

Actually I've been searching my error and i found tons of solutions but they couldn't fix my problem and probably this is easy but i can't handle...

/* header */
class EmployeeRegister
{
private:
    EmpReg *Emp;
public:
    EmployeeRegister(int,int);
};


/* cpp file*/
EmployeeRegister::EmployeeRegister(int a,int b)
{
    cout << "Result  : " << a+b << endl;
}


/* in main file*/
EmployeeRegister Sub(1,1);

and when i do this or something like this i get :

main.obj:-1: error: LNK2001: unresolved external symbol "public: 
   __thiscall EmployeeRegister::EmployeeRegister(int,int)" 
   (??0EmployeeRegister@@QAE@HH@Z)

Actually I'm sure this is easy but what am I missing ?

EDIT : It's fixed , linker couldn't find my .cpp file.

2 Answers2

2

Make sure your non-main .cpp file is listed in the project (or in linker command-line) so that it can be properly linked with your main.cpp

YePhIcK
  • 5,816
  • 2
  • 27
  • 52
1

As you are a newbie,

Please mention how do you build the project. You should compile both main.cpp and EmployeeRegister.cpp and link both main.o and EmployeeRegister.o files.

g++ -c Main.cpp g++ -c EmployeeRegister.cpp g++ -o binaryname Main.o EmployeeRegister.o

Sujith Gunawardhane
  • 1,251
  • 1
  • 10
  • 24