Search code examples
c++classoopstdvector

Getting error while trying to exercise on objects and vectors and how they run together


#include <iostream>
#include <vector>

using namespace std;

class Bank_Account
{
    private:
        string Account_Owner_Name;
        string Account_Owner_Surname;
        float Account_Balance;
        float Account_Remaining_Loan;
    public:
        Bank_Account()
        {

        }
        Bank_Account(string Name, string Surname)
        {
            Account_Owner_Name=Name;
            Account_Owner_Surname=Surname;
            Account_Balance=0;
            Account_Remaining_Loan=0;
        }
        
        void get_Account_Info()
        {
            cout << Account_Owner_Name << " " << Account_Owner_Surname << ":" << endl;
            cout << "Balance: " << Account_Balance << endl;
            cout << "Loan: " << Account_Remaining_Loan; 
        }
};

int main()
{   
    string Register_Name, Register_Surname;
    Bank_Account New_Account;
    vector <Bank_Account> Accounts;
    cout << "Register new account?" << endl;
    cin >> Register_confirmation;
    if (Register_confirmation==true)
    {
        cout << "\nName: "<< endl;
        cin >> Register_Name;
        cout << "\nSurname: ";
        cin >> Register_Surname;
        New_Account(Register_Name, Register_Surname);
        New_Account.get_Account_Info();
        Accounts.push_back(New_Account);
    }

"call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type" is the error I get when i compile it. I am still in the beginning of OOP and classes, so some of the stuff are new to me. Any corrections are welcome too. Thanks!!!


Solution

  • To do

    New_Account(Register_Name, Register_Surname);
    

    An operator() that takes two arguments has to be defined in the class Bank_Account.

    It looks like you wanted to do

    New_Account = Bank_Account(Register_Name, Register_Surname);