I am new to classes and was trying to create an elmentary program to understand classes and objects.
I ve created three files
1) header file for class declaration
2) class definition .cpp file
3) class implementation main .cpp file
I cannot understand the error I am getting. Please help.
"1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall sum::add(int,int)" (?add@sum@@QAEXHH@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall sum::sum(void)" (??0sum@@QAE@XZ) referenced in function _main
1>c:\users\haider\documents\visual studio 2010\Projects\Learn_class\Debug\Learn_class.exe : fatal error LNK1120: 2 unresolved externals
"
Please see below my code for the files.
//1) Header file sum.h
class sum
{
public:
sum ();
void add(int , int);
};
// 2)Class defination file
#include<iostream>
#include "sum.h"
using namespace std;
void sum::add(int a, int b)
{ int c;
c=a+b;
cout<<"sum is: "<<c;
}
//3) Class implementation file
#include<iostream>
#include "sum.h"
using namespace std;
int main()
{
sum sum1;
int a,b;
cout<<"enter the nos";
cin>>a>>b;
sum1.add(a,b);
}