大家好,我是编程新手,所以请原谅菜鸟问题...我尝试了所有方法来解决未定义的引用错误,但它一直向我抛出该错误我尝试使用指针“->”和“::”符号和还有点“。” 我应该做些什么?为什么不能编译?
这是我的 cpp 文件:
#include <cstdlib>
#include "account.hpp"
using namespace std;
int Account::getAccountNumber()
{
return accountNumber;
}
double Account::getBalance()
{
return balance;
}
void Account::createAccount(LinkedList<Account>& accountsList, string name, int idNumber)
{
...
case 1:
accountsList.addFront(newAcc); //Where the error occurs.
break;
case 2:
do
{
cout << "\n\tWhich position would you like to insert the\n"
<< "\tnew account into?\n"
<< "\tPosition number: #";
cin >> target;
if (cin.fail())
{
cin.clear();
cin.ignore(20,'\n');
cout << "\n\n\tSorry, wrong input. Please enter a correct position.\n\n";
system("pause");
}
}
while(cin.fail());
accountsList.addMiddle(newAcc, target); //and here
break;
case 3:
accountsList.addEnd(newAcc); //and here
break;
}
cout << "\n\n\tAccount Created Successfully\n\n"
<< accountsList;
system("pause");
}
这是我的.hpp
#ifndef ACCOUNT_HPP_INCLUDED
#define ACCOUNT_HPP_INCLUDED
#include "linkedlist.hpp"
#include "generic.hpp"
class Account : public GenericAccount
{
int accountNumber;
double balance;
public:
Account(string name = "empty", int idNumber = 0, int accountNumber = 0, double balance = 0)
: GenericAccount(name, idNumber), accountNumber(accountNumber), balance(balance) {}
int getAccountNumber();
double getBalance();
void createAccount(LinkedList<Account>&, string, int);
void deposit(LinkedList<Account>&, Account&);
void withdraw(LinkedList<Account>&, Account&);
void displayAccount(LinkedList<Account>&, Account&);
void deleteAccount(LinkedList<Account>&);
friend istream& operator>> (istream& is, Account& x)
{
is >> x.accountNumber;
return is;
}
friend ostream& operator << (ostream& os, Account& c)
{
os << "Account Number= " << c.getAccountNumber() << "\t"
<< "Balance= "<< c.getBalance() << endl;
return os;
}
friend bool operator == (Account& a, Account& target)
{
return (a.getAccountNumber() == target.getAccountNumber());
}
};
#endif // ACCOUNT_HPP_INCLUDED
完整的项目可以在这里下载以供参考 提前谢谢大家!