Chào mọi người, tình hình là em có viết 1 cái code như sau:
//Account.h
#include<iostream>
class Account{
private:
float _income;
float _expense;
void balance();
public:
Account();
Account(int, int);
void display()const;
Account& operator+=(const Account& f);
friend bool operator==(const Account&, const Account&);
};
Account operator+(const Account&, const Account&);
-----------------------------------------------------
//Account.cpp
#include<iostream>
#include "Account.h"
using namespace std;
//Constructor
Account::Account(){
_income=0;
_expense=0;
}
//Overload constructor
Account::Account(int income, int expense){
_income=income;
_expense=expense;
}
//Function balance
void Account::balance(){
if(_income >_expense){
_income=_income-_expense;
_expense=0;
}
else{
_expense=_expense-_income;
_income=0;
}
}
//Display income and expense
void Account::display()const {
cout<<_income;
cout<<_expense;
}
//compound assignment operator with +=
Account& Account::operator+=(const Account& f){
_income += f._income;
_expense += f._expense;
balance();
return *this;
}
//helper function, Account operator
Account operator+(const Account& a, const Account& b){
Account temp = a;
temp += b;
return temp;
}
//using keyword friendship
//Function bool operator
bool operator==(const Account& acc, const Account& bcc){
if((acc._income == bcc._income) && (acc._expense==bcc._expense)){
return true;
}
else{
return false;
}
}
tình hình là em có gặp 1 lỗi: Error 4 error C2146: syntax error : missing ‘;’ before identifier ‘result’
và lỗi Error 3 error C2065: ’ return’ : undeclared identifier
mọi người có thể cho em hỏi lỗi này là lỗi gì không và làm sao để sửa lỗi này. Em tìm hiểu trên mạng qua nhưng không tìm được giải pháp.
Cám ơn mọi người
Mới học lập trình nhiều trường hợp thế này lắm.
cám ơn anh giúp đỡ
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?