#include <iostream>
using namespace std;
class gra
{
private:
int g;
int g2;
public:
gra();
gra(int a,int b);
gra add(const gra& rhs);
};
gra::gra(int a,int b)
{
g=a;
g2=b;
}
gra gra::add(const gra& rhs)
{
gra sum;
sum.g=g+rhs.g;
sum.g2=g2+rhs.g2;
return sum;
}
int main()
{
gra p1(34,12);
gra p2(13,65);
gra ad;
ad=p1.add(p2);
}
This is my program when i build it gives this error
unresolved external symbol "public: __thiscall gra::gra(void)" (??0gra@@QAE@XZ) referenced in function "public: class gra __thiscall gra::add(class gra const &)" (?add@gra@@QAE?AV1@ABV1@@Z)
Your class doesn't have the default constructor's implementation. When you declare gra sum; the compiler will init sum with the default constructor which you don't implement it yet.