简体   繁体   中英

Function does not take 3 arguments C++ error? [on hold]

I have a bank account system where I am trying to make an account. I have tried changing the variables in the header file. But I keep getting the error when I am calling the method set Account:

 1>C:\Users\hamza\source\repos\Account\Account\Accountexample.cpp(9,38): error C2660: 'Account::setAccount': function does not take 3 arguments
1>Generating Code...
1>C:\Users\hamza\source\repos\Account\Account\Account.h(11,7): message : see declaration of 'Account::setAccount'
1>Done building project "Account.vcxproj" -- FAILED.

My Account Class:

    #include "pch.h"
#include "Account.h"

using namespace std;

Account::Account()
{
    id = "";
    name = "";
    balance = 0;
}

Account::~Account()
{
}

void Account::credit(double amount) {
    balance += amount;
}

void Account::setAccount(string id, string name, double balance) {
    id = "insert id";
    name = "insert name";
    balance = 0;


}
void Account::printAccount() {
    cout << "\naccount id is " << id << "account name is" << name << "account balance is " << balance;
}

Class where I am printing from(Accountexample):

 #include "pch.h"
#include "Account.h"

using namespace std;

int main()
{
    Account t;
    t.setAccount("2321", "32312", 213.50);

    return 0;
}

Here is the header file(Account.h):

    #pragma once
class Account
{
public:
    Account();
    ~Account();
    void credit(double);
    void debit(double);
    void getbalance();
    void printAccount();
    void setAccount(string id, string name, double balance);

private:
    string id;    //0-23
    string name;  //0-59
    double balance;  //0-59
};

I have managed to get the answer. It is to add using namesapce std to the header file:

 #pragma once
using namespace std;
class Account1
{
public:
    Account1();
    ~Account1();
    void setAccount(string id, string name, double balance);
    void credit(double);
    void debit(double);
    void getbalance();
    void printAccount();

private:
    string id;    //0-23
    string name ;  //0-59
    double balance;  //0-59
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM