문제

hi everyone im new to programming so excuse the noob question... i tried every method to get through with the undefined refernce error but it keeps throwing that error at me i tried using pointer "->" and the "::" sign and also the dot "." what am i supposed to do? why cant it compile?

this is my cpp file:

#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");
}

and here is my .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

the full project can be downloaded HERE for refernce THANK YOU ALL IN ADVANCE!

도움이 되었습니까?

해결책

I think the issue is that there is that the addFront method is not being defined for the account type (in fact any type). See Why can templates only be implemented in the header file? for a much better explanation.

Moving the contents of cpp inline in the .h file should do the trick. Another option is to rename the the .cpp file to a .inl and include it at the bottom of linkedList.hpp

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top