DEVC++ 编译时出现[Error] ld returned 1 exit status可能错误

DEVC++ 编译时出现[Error] ld returned 1 exit status可能错误

DEVC++编译时经常出现[Error] ld returned 1 exit status类似错误,除了可能的主函数名写错、已经运行了一个命令窗口外
还有可能是,函数声明了,但是忘记了定义。本人是h文件中声明了BankAccount(),但是在cpp源文件中忘记了定义BankAccount()的内容,错误找了很长时间。

#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H

#include 
#include 

class BankAccount
{
	private:
		std::string name;
		std::string account;
		int number;
	public:
		BankAccount();
		BankAccount(std::string nam, std::string acco,int num);
		~BankAccount();
		void showbankaccount(const BankAccount &B);
		void depoist(BankAccount &B, int num);
		void withdraw(BankAccount &B, int num);
};

#endif
#include  
#include "BankAccount.h"
//using namespace std;
BankAccount::BankAccount() ;
{
	name="no name";
	account="no account";
	number=0; 
}

BankAccount::BankAccount(std::string nam, std::string acco, int num)
{
	name=nam;
	account=acco;
	number=num;
}
void BankAccount::showbankaccount(const BankAccount &B)
{

	std::cout<<"Here is your account informaiton:\n";
	std::cout<<"Name: "<<B.name<<std::endl;
	std::cout<<"Account: "<<B.account<<std::endl;
	std::cout<<"Balance: "<<B.number<<std::endl; 
}
void BankAccount::depoist(BankAccount &B, int num)
{
	B.number+=num;
}

void BankAccount::withdraw(BankAccount &B, int num)
{
	if(num>B.number)
	{
		std::cout<<"You do not have so much money!"<<std::endl;
//		break;
	}
	else
	B.number-=num;
}
BankAccount::~BankAccount()			//析构函数未定义导致编译失败,本题中,函数声明了就要定义 
{
	std::cout<<"_________________"<<std::endl;
 } 
#include 
#include "BankAccount.h"
#include 

int main() 
{

	BankAccount bankact1("Jack", "ABC", 900);
	BankAccount bankact2;
	bankact1.showbankaccount(bankact1);
	bankact1.depoist(bankact1,200);
	bankact1.showbankaccount(bankact1);
	bankact1.withdraw(bankact1,1000);
	bankact1.showbankaccount(bankact1);
	bankact2.showbankaccount(bankact2);
	return 0;

}

你可能感兴趣的:(C++)