Jump to content

Linked list Error

- - - - -

  • Please log in to reply
8 replies to this topic

#1
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts

#ifndef AccountId

#define AccountId

#include <string>

#include <iostream>


using namespace std;


class Account

{

private:   

    string coursename;	

	int courselevel;

	int coursecredit;

	string coursecode;

	Account *nextAccount; 

	Account *head;


public:	

	

    Account();//default Constructor

    Account(string,string,int,int);//primary constructor

    ~Account();//destructor   

    Account * getNextAccount(); //gets the next account pointer

    void setNextAccount(Account *); //sets the next account pointer

    void Display();

	void AddNode(string,string,int,int);

	void DisplayList();

	void DestroyList();

};

#endif





#include "Account.h"

#include <string>

#include <iostream>


using namespace std;


Account::Account(string an, string  ab , int ac , int ax) //primary constructor

{

	coursename = an;

	coursecode = ab;

	courselevel = ac;

	coursecredit = ax;	

	nextAccount = NULL;

	head = NULL;

}


void Account::DisplayList()

{

	Account *temp = head;

	while (temp != NULL)

	{

		temp->Display();

		temp = temp->getNextAccount();

	}

}


void Account::AddNode(string an, string  ab , int ac , int ax)

{

	//make the new node

	Account *node  = new Account(an,ab,ac,ax);	

   

    //if memory was sucessfully allocated

    if (node != NULL)

	{

         //if this is the first node to be added 

        //or if list is empty

		if (head == NULL)

		{

			head = node;//make the first element

		}

		else

		{   ///if the list is not empty

			

            Account *temp = head;

            while(temp->getNextAccount() != NULL)

				temp = temp->getNextAccount();//points temp to the next element

			temp->setNextAccount(node);//the end is reached we insert the element

		}

	}


	else


	{

		cout << "Error - out of memory while creating new node." << endl;

	}

}


Account::~Account() //destructor

{

	/*cout << "\nDestructor for node [" << getAccountNum() << "," << 

		getAccountBal() << "]\n\n";*/

}



Account * Account::getNextAccount() //accessor for nextAccount pointer

{

	return nextAccount;

}


void Account::setNextAccount(Account *na) //mutator for nextAccount pointer

{

	nextAccount = na;

}


void Account::Display() //Display information in node

{

	cout << coursename << " " << coursecode <<  " " << courselevel << " " << coursecredit;

	cout << "\n";

}


void Account::DestroyList()

{

	Account *temp;

	while (head != NULL)

	{

		temp = head;

		head = head->getNextAccount();

		delete temp;

	}

}





void main()

{

		Account BankAccounts;


		string coursename;

		string coursecode;

		int courselevel;

		int coursecredit;


		//Creates a file stream for the room text file and opens it for reading

		fstream file;

		file.open( "Courses.txt", ios::in);


		if ( !file )

			 {

				cout << "Error";

				cout <<"\n\n";

			 } 

		else

		{	

		

			//Read the contents of the file

			while(file >> coursename >> coursecode >> courselevel >> coursecredit)

			{	

				BankAccounts.AddNode(coursename,coursecode,courselevel,coursecredit);

			}

		}

  


		BankAccounts.DisplayList();

		BankAccounts.DestroyList();


	

   cin.get();




}



I am getting an error

Error 1 error LNK2019: unresolved external symbol "public: __thiscall Account::Account(void)" (??0Account@@QAE@XZ) referenced in function _main C:\Users\Donellie Whyte\Desktop\test\test\Driver.obj


Error 2 error LNK1120: 1 unresolved externals C:\Users\Donellie Whyte\Desktop\test\Debug\test.exe

Edited by hbk, 05 March 2011 - 10:16 AM.


#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
You need to tell us the line number and error, you can't expect us to attempt to compile your code.

#3
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts
The compiler was just talking about some link error in main and it never gave me a line.

#4
jcampos8782

jcampos8782

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
Well what was the error? "Some link error" is hardly an explanation

#5
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts
Error Is:

Error 1 error LNK2019: unresolved external symbol "public: __thiscall Account::Account(void)" (??0Account@@QAE@XZ) referenced in function _main C:\Users\Donellie Whyte\Desktop\test\test\Driver.obj


Error 2 error LNK1120: 1 unresolved externals C:\Users\Donellie Whyte\Desktop\test\Debug\test.exe

#6
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
I'm not sure about those errors, but you need int main() which returns 0 upon success. You're also missing definition of default constructor.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
What is the command-line you are issuing? I suspect you aren't using the right command.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#8
Xupicor

Xupicor

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
I wouldn't say that WingedPanther, Flying Dutchman already pointed out that there is a declaration and a lack of definition of default constructor. The object is then created using default constructor... How would the compiler know what do to when there's no definition of it? ;)

The error even mentions the said constructor in the message.

#9
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts
It solves my compilation problem and the error. But I am getting an exception at the following in the cpp file for the account.

Account * Account::getNextAccount() //accessor for nextAccount pointer

{

	return nextAccount;

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users