"head" not recognized

I'm getting a strange error indicating that head isn't recognized even though I include the header file "class_list.h" in my class_list.cpp file. I've tested to see if I can declare other c_node pointer types within my implementation files for the function and it doesn't give me any trouble except when I declare c_node pointer types in private. Could anyone help me understand what I'm doing wrong? **Note** messages.h has <cstring>, <cctype>, <iostream> included.

.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
	The purpose of this class is to contain all of the chatrooms and messages between users.
	The chatrooms will store the users involved in each chatroom and the messages each user has sent.

*/

#include "messages.h"

struct c_node 
{
	char * c_room_name;
	user * users;
	c_node * next;
	
	//class of messages
	//messages chat_message;
};


class chat_list
{
	public:
		//constructors and deconstructor
		chat_list();
		~chat_list();
		
		//called from client program. Sends the chat_name to the set_username 
		//function invokes the set_username function to store the contents of
		//username into the class objects


		//Sets the name of the chatroom and creates a new LLL
		//The title of this LLL features as the chatroom
		bool create_chatroom(const char * room_name, user & users_from);
	
	private:
		c_node * head;
		c_node * tail;

};


.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "chat_list.h"

chat_list::chat_list()
{
	head = NULL;
	tail = NULL;
}


chat_list::~chat_list()
{
	/*
	if(!head && !tail)
		delete head;
	else
	{
		c_node * current = head;
		while(current != tail)
		{
			current = current->next;
			delete head;
			head = current;
		}
		head = current = NULL;
		delete tail;
		tail = NULL;
	}
	*/	
}


bool create_chatroom(const char * room_name, user & users_from)
{
	if(!room_name)
		return false;
	if(!head)
	{
		head->c_room_name = new char [strlen(room_name) + 1];
		strncpy(head->c_room_name, room_name, strlen(room_name));
		return true;

		head->c_users.copy_user(users_from);

		cout << "Inside of list node! " << endl;
		head->c_users.display();
	}
	else if(!head->next)
	{
		create_chatroom(room_name, head->next);
		return true;
	}
	else
		create_chatroom(room_name, head->next);	
}
1
2
3
bool chat_list:: create_chatroom(const char * room_name, user & users_from)
{
   ...


I'm getting a strange error indicating that head isn't recognized even though I include the header file "class_list.h" in my class_list.cpp file.


Your function "create_chatroom()" is not a class member function. Perhaps you forgot to properly scope the function into the chat_list:: class?

Also where are you allocating memory for those pointers (*head and *tail)?

Also when the program encounters a return statement nothing after that return statement is executed, so lines 42 through 45 will never be executed.

Topic archived. No new replies allowed.