Ich erhalte den FehlerC++ Fehler „ungültig Konstruktor, Sie wahrscheinlich gemeint‚Account (konst Account &)
ungültig Konstruktor;. Sie wahrscheinlich
Account (const Account&)
gemeint
explicit Account (Account balance) {
: accountBalance (balance);
}
Ich habe versucht, Ändern der Eingabe zu (Account balance)
und versuchte auch mit (int balance)
. int Gleichgewicht gibt mir einen Fehler
"erwarteter Primärausdruck vor ':' Token.
Voll Code
#include <iostream>
#include <string>
using namespace std;
class Account {
public:
explicit Account (Account balance) {
: accountBalance (balance);
}
void setAccountBalance (int balance) {
accountBalance = balance;
}
int getAccountBalance() const {
return accountBalance;
}
void displayBalance() const {
std::cout << "Welcome to the Account. The balance is : $" << getAccountBalance() << std::endl;
}
private:
int accountBalance;
};
int main() {
int startBalance = 0;
Account myAccount1;
cout << "Initial Dollar Amount is : " << myAccount1.getAccountBalance() << endl;
cout << "Please enter new balance : " << endl;
cin >> startBalance;
myAccount1.setAccountBalance(startBalance);
myAccount1.displayBalance();
}
Ahh ja danke. Ich sehe jetzt, dass ich setzen: accountBalance (balance); Innerhalb der Funktion des expliziten Accounts (int balance). Und ich legte auch ein Semikolon am Ende. ^.^Danke für deine Hilfe. – Greg
@Greg Sie willkommen! .. Sie könnten eine der Antworten auf Ihre Frage akzeptieren .. für weitere Informationen http://StackOverflow.com/Help/accepted-answer – HazemGomaa