-1

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!

user2657029
  • 43
  • 1
  • 3
  • [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – gx_ Aug 24 '13 at 17:30
  • Is it `my.hpp` or `account.hpp` because you have included the latter in my.ccp – Uchia Itachi Aug 24 '13 at 17:38
  • @gx_ thanks for the link i already check it out during my search for an answer – user2657029 Aug 25 '13 at 13:06
  • @UchiaItachi i meant thats my .hpp file not a file named my.hpp, sorry about the confusion – user2657029 Aug 25 '13 at 13:06

1 Answers1

0

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

Community
  • 1
  • 1
luke
  • 1,024
  • 3
  • 11
  • 21