
请各位大哥大姐帮帮我吧..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
大虾们...再帮帮我吧...谢谢了! 展开
#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
大虾们...再帮帮我吧...谢谢了! 展开
2个回答
展开全部
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;
}
{
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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询