尝试对对象和向量进行练习时出现错误以及它们 运行 在一起的方式
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);
}
“在没有适当的 operator() 或将函数转换为函数指针类型的情况下调用 class 类型的对象”是我在编译时遇到的错误。我仍处于 OOP 和 classes 的初级阶段,所以有些东西对我来说是新的。也欢迎任何更正。谢谢!!!
要做
New_Account(Register_Name, Register_Surname);
需要两个参数的 operator()
必须在 class Bank_Account
中定义。
看起来你想做
New_Account = Bank_Account(Register_Name, Register_Surname);
#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);
}
“在没有适当的 operator() 或将函数转换为函数指针类型的情况下调用 class 类型的对象”是我在编译时遇到的错误。我仍处于 OOP 和 classes 的初级阶段,所以有些东西对我来说是新的。也欢迎任何更正。谢谢!!!
要做
New_Account(Register_Name, Register_Surname);
需要两个参数的 operator()
必须在 class Bank_Account
中定义。
看起来你想做
New_Account = Bank_Account(Register_Name, Register_Surname);