Greg Greg - 1 year ago 121
C++ Question

C++ error "invalid constructor; your probably meant 'Account (const Account&)

I keep getting the error "invalid constructor; your probably meant 'Account (const Account&). It's for line 10 of the code ...

explicit Account (Account balance) {
: accountBalance (balance);

I've tried changing the input to be (Account balance) and tried also using (int balance). int balance gives me an error of "expected primary-expression before ':' token.

Full code is...

#include <iostream>
#include <string>

using namespace std;

class Account {


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;

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;


cout << endl;


Answer Source

you need to fix your constructor and the initialization list, as follows

explicit Account (int balance):accountBalance (balance){}

you need to provide an argument when creating Account object, as follows

int startBalance = 0;
Account myAccount1(startBalance);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download