注册 登录
编程论坛 C++教室

在线等 菜鸟问题

忘记喧嚣 发布于 2007-11-28 22:16, 678 次点击
这个是错误
--------------------Configuration: fig_account - Win32 Debug-------------------- Compiling... fig_account.cpp Linking... fig_account.obj : error LNK2001: unresolved external symbol "public: int __thiscall Account::debit(void)" ([email=?debit@Account@@QAEHXZ]?debit@Account@@QAEHXZ[/email])
fig_account.obj : error LNK2001: unresolved external symbol "public: int __thiscall Account::crddit(void)" ([email=?crddit@Account@@QAEHXZ]?crddit@Account@@QAEHXZ[/email])
fig_account.obj : error LNK2001: unresolved external symbol "public: __thiscall Account::Account(int)" (??0Account@@QAE@H@Z) Debug/
fig_account.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. fig_account.exe - 4 error(s), 0 warning(s)

编一个程序实现存款和取款 然后写两次测试对象
-----------------------------------------
//Account.h
#ifndef  ACCOUNT_H
#define  ACCOUNT_H
class Account
{
public:
     Account(int);

  int crddit( );
  int debit();
  void setBalance(int);
  int getBalance();
private:
int blance;
};
#endif
--------------------------------------------------------------
//Account.cpp
#include<iostream>
using namespace std;
#include "Account.h"

Account::Account(int i)
{
  if(i>=0)
     setBalance(i);
  
  else
  {
   setBalance(0);
   cout<<"invalid number";
  }
}

  int Account::crddit()
  {
   int add=0;
  cout<<"input you want to add to number:";
  cin>>add;
  blance+=add;
  cout<<"the blance after add:"<<getBalance()<<endl;
  
  }

  int Account::debit()
  {
   int dicre=0;
  cout<<"input you want to dicre number:";
  cin>>dicre;
  if (dicre<=blance)
  {
   blance-=dicre;
   cout<<"the blance after dicre:";
  }
   else
   cout<<"Debit amount exceeded account blance"<<getBalance()<<endl;
   
  }
  void Account::setBalance(i)
   {
     blance=i;
   }
  int Account::getBalance()
  {
   return balance;
  }
--------------------------------------------------------------------
//fig_account.cpp
#include<iostream>
using namespace std;
#include"Account.h"
int main()
{
Account account1(50);
Account account2(-50);
account1.crddit();
account1.debit();
account2.crddit();
account2.debit();
return 0;

}

谢谢帮小弟看看哈.
我用的是英文版的 VC++6.0
2 回复
#2
VxWorks2007-11-28 22:23
VC++6.0不支持类的定义和成员函数分开实现,你把Account.h和Account.cpp放到一个文件中就行了。建议学c++换用对标准支持好的编译器,毕竟VC++6.0是98年出来的,到现在c++标准已经有了不少变化。你可以试试VC2005或Dev-c++
#3
忘记喧嚣2007-11-28 22:24
谢谢你哈
1