I had written a program in C++, called Accounts.
Here Account is the base class and CA and SA the derived classes.
A function statement() is a virtual function in the base and redefined in each of the derived classes.
Code:
class Account
{
private:
int Acc;
char name[20];
public:
Account();
Account(int);
virtual ~Account();
virtual void withdrawals(const float&) = 0;
virtual float get_interest () const = 0;
virtual void statement () const = 0;
void print() const;
};
Redinitions in CA and SA are
Code:
void statement() const;
The code is different in each case.
The program compiles properly, but I get a linker error
Account.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Account::statement(void)const " (?statement@Account@@UBEXXZ)
Debug/Accounts.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
The statement function is as follows
Code:
//in derived class CA (Current Account)
void CA::statement() const
{
print();
float I;
I = (*this).get_interest();
cout <<"\n Type : Current Account";
cout <<"\n Savings = "<<Savings;
cout <<"\n Interest earned is "<<I;
cout <<"\n Thanks";
}
//inderived class SA Savings Account
void SA::statement() const
{
print();
float I;
I = (*this).get_interest();
cout <<"\n Type : Savings Account";
cout <<"\n Savings = "<<Savings;
cout <<"\n Interest earned is "<<I;
cout <<"\n Savings (with Interest) = "<<Savings + I;
cout <<"\n Thanks";
}
The print() function is defined in the base class
Code:
//print function in base class Account
void Account:: print() const
{
cout << "\n A/C No. "<< Acc;
cout <<"\n A/C holder: "<<name;
}
This print() function is not redefined in any derived class. i am at wits end trying to figure why I am getting this linker error (in compiles perfectly). I am using Microsoft Visual C++ 6.0.
Could Someone please help ???