请各位大哥大姐帮帮我吧..C++ calss问题

Account.h#include<iostream>usingstd::string;classAccount{public:Account(int);//构造函数vo... Account.h
#include<iostream>

using std::string;

class Account
{
public:
Account( int ); //构造函数
void credit( int ); // 银行存款
void debit(); // 取钱
void getBalance( int ); //返回当前余额
private:
int balance;
};

Account.cpp
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include "Account.h"

Account::Account( int balance)
{
credit( balance );
}

void Account::credit( int balnace )
{
int money; //加入的金额
int total; //总数
total = total + money;
}

void Account::debit()
{
int drawout; //取款的金额
int balance; //余额
if (drawout<balance)
{
balance = balance - drawout;
}
else
cout<<"Debit amount exceeded account balance!";
}

void Account::getBalance
{
return balance;
}

Account2.cpp

#include "Account.h"

int main()
{
Account myAccount;

int balance;

myAccount.credit( balance );
myAccount.debit( );
return 0;
}

编译的时候,出现了一下问题:
1.error C2182: 'getBalance' : illegal use of type 'void'
2.fatal error C1903: unable to recover from previous error(s); stopping compilation

希望大家能够帮帮我修改一下吧..小弟在此谢过!
还是有错误喔...
fatal error C1001: INTERNAL COMPILER ERROR
大虾们...再帮帮我吧...谢谢了!
展开
 我来答
newghost_joe
2007-03-02 · TA获得超过791个赞
知道小有建树答主
回答量:1915
采纳率:0%
帮助的人:1201万
展开全部
void Account::getBalance
{
return balance;
}
....void 怎么能返回呢?

Account.h
#include<iostream>

using std::string;

class Account
{
public:
Account( int ); //构造函数
void credit( int ); // 银行存款
void debit(); // 取钱
int getBalance( int ); //返回当前余额
private:
int balance;
};

Account.cpp
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include "Account.h"

Account::Account( int balance)
{
credit( balance );
}

void Account::credit( int balnace )
{
int money; //加入的金额
int total; //总数
total = total + money;
}

void Account::debit()
{
int drawout; //取款的金额
int balance; //余额
if (drawout<balance)
{
balance = balance - drawout;
}
else
cout<<"Debit amount exceeded account balance!";
}

int Account::getBalance
{
return balance;
}

Account2.cpp

#include "Account.h"

int main()
{
Account myAccount;

int balance;

myAccount.credit( balance );
myAccount.debit( );
return 0;
}
usosr
2007-03-02 · TA获得超过129个赞
知道答主
回答量:208
采纳率:0%
帮助的人:0
展开全部
getBalance的返回值是void 但又return了

int getBalance( int ); //返回当前余额

int Account::getBalance
{
return balance;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式