C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 12th, 2005, 06:34 PM
vinceb1 vinceb1 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 vinceb1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 17 sec
Reputation Power: 0
Question linked list problems (newbie programmer)

okay here is my text the problem is is that i just cant for the life of me debug there are 2 errors that i can work around, i used to have the .h and .cpp files as seperate files but got these errors

---------- C++ Compiler ----------
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
mainRoom.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external 'RoomList::RoomList()' referenced from C:\DOCUMENTS AND SETTINGS\VINCE\DESKTOP\LINKED LIST WORK\MAINROOM.OBJ
Error: Unresolved external 'Room::Room()' referenced from C:\DOCUMENTS AND SETTINGS\VINCE\DESKTOP\LINKED LIST WORK\MAINROOM.OBJ
Error: Unresolved external 'RoomList::AddToHead(Room)' referenced from C:\DOCUMENTS AND SETTINGS\VINCE\DESKTOP\LINKED LIST WORK\MAINROOM.OBJ
Error: Unresolved external 'RoomList::Print()' referenced from C:\DOCUMENTS AND SETTINGS\VINCE\DESKTOP\LINKED LIST WORK\MAINROOM.OBJ
Normal Termination
Output completed (0 sec consumed).

so i then put it all in 1 file so it dont have to mission it about for the files and came up with this

Code:
 //mainRoom.cpp
#include <iostream.h> 
/////////////////////////////////////////////////////////////////////////////
#ifndef room
#define room
class Room 
{
 int  floor,number;
 char building; //'M','A','W','L' or ''
 
public:
//void Print(); // Print the Room
//Room();  // Constructor
void Room :: Print()
{
 cout << "Floor [" << floor << "]" << endl;
 cout << "Room [" << number <<"]" << endl;
 cout << "Building [" << building <<"]" << endl;
}
Room::Room()
{
 cout << "** Enter Room Details **" << endl;
 cout << "Input floor number ->";
 cin >>floor;
 cout << "Input room number ->";
 cin >>number;
 cout << "Input building ID  ->";
 cin >>building;
}
};
#endif
////////////////////////////////////////////////////////////////////////////////
#ifndef roomnode
#define roomnode
//#include "room.h"
class RoomNode
{
 Room room;
 RoomNode* p_next;
public:
 friend class RoomList;	 // make account list a friend 
 RoomNode(Room a, RoomNode *p_n);//constructor
}
RoomNode::RoomNode(Room a,*p_n)
: room(a)  //initializer list :)
{
 p_next=p_n;
};
#endif

///////////////////////////////////////////////////////////////////////////////
#ifndef rooml
#define rooml
//#include "room.h"
//#include "roomnode.h"
class RoomList{
 RoomNode *p_head;
public:
//void AddToHead(Room a);
// Print();
//RoomList();
void RoomList :: AddToHead(Room a)
{
 p_head = new RoomNode(a,p_head);
}
void RoomList :: Print()
{
RoomNode *p_temp = p_head;
 
 while (p_temp !=0)
  {
   p_temp->room.Print();
   p_temp = p_temp->p_next;
  }
}
RoomList::RoomList()
{
 p_head = 0;
}
};

#endif
////////////////////////////////////////////////////////////////////////////////
#ifndef roomnode
#define roomnode
//#include "room.h"
class RoomNode
{
 Room room;
 RoomNode* p_next;
public:
 friend class RoomList;	 // make account list a friend 
 RoomNode(Room a, RoomNode *p_n);//constructor
 
RoomNode::RoomNode(Room a, RoomNode *p_n)
: room(a)  //initializer list :)
{
 p_next=p_n;
}
};
#endif
////////////////////////////////////////////////////////////////////////////////
main()
{
RoomList al;
char choice;
do
 {
 cout << "\n(A)dd room, (P)rint, (Q)uit ->";
 cin >> choice;
 switch(choice)
  {
   case 'A' : { Room newRoom;
	   al.AddToHead(newRoom);
	   break;
		}
   case 'P' :  al.Print();
	   break;
		}
  
 }
 while (choice !='Q');
};


but with the above i get 2 compilation errors that i just cant fix any ideas any1 any help greatly appreciated thanks alot

Vince

Reply With Quote
  #2  
Old April 13th, 2005, 10:40 PM
astralvoid astralvoid is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 9 astralvoid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 2 m 42 sec
Reputation Power: 0
If you are defining your member function within the class declaration, you do not need to specify the Room:: scope operator..you are already in scope.

Just remove the Room:: on function that are defined within the class declaration.

eg.

Code:
  
  class myClass
  {
    public:
  	myClass()   //constructor
  	{
  	   i = 0;
  	 }
  
     void printit()  
     {
  	  cout << i;
  	}
  
  private: 
     int i;
  
  }; //end class 
  



Notice that because I defined the member functions within the class declaration, I did not need to use the myClass:: scope resolution.

Hope this helps!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > linked list problems (newbie programmer)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT