初学C++中遇到的问题
下面定义一个简单类Account,这个类记录一个账号和关于这个账号的款额.可以对这个类进行的操作是存款,取款,查看余额,取账号等.下面是程序代码:account.h
class Account{
public:
Account(int id,float amount=0);
float GetBalance(){return balance;}
void Save(float amount);
bool Withdraw(float amount);
int GetAccountID(){return accountID;}
private:
int accountID;
float balance;
};
account.cpp*************************
# include "account.h"
inline Account::Account(int id,float amount)
{
accountID=id;
balance=amount;
}
inline void Account::Save(float amount)
{
balance+=amount;
}
bool Account::Withdraw(float amount)
{
if(balance<amount)
return false;
balance-=amount;
return true;
}
main.cpp***************************
#include <iostream.h>
#include "account.h"
void main()
{
Account a(1,100.0);
}
main.cpp进行编译无错误,可是进行连接时就出错了错误代码如下:
------------Configuration: main - Win32 Debug--------------------
Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall Account::Account(int,float)" (??0Account@@QAE@HM@Z)
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
main.exe - 2 error(s), 0 warning(s)