| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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!! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > linked list problems (newbie programmer) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|