return doesn't work but cout does?

this function from my class returns the size of length of the linked list.

1
2
3
4
5
6
7
8
9
10
11
12
  int LinkedList::GetLength()
{
	int count = 0;
	Node* temp = head;
	while (temp!=0)
	{
		count++;
		temp = temp->next;
	}
	//cout << count;     <-- this works
	return count;
}
What do you mean doesn't work? Does the function not return the same value that is printed?
it doesnt return anything at all. just a blank space
That's impossible. It's returning an int, which will be 4 (or eight) bytes in size, and that memory will contain some value because it's impossible for it to not contain some value.

So what makes you think it's somehow a blank space?
Note that return doesn't automatically print the value. To print the value you need to do it explicitly.

 
cout << yourList.GetLength();
Last edited on
output with return
1
2
3
4
5
6
7
8
9
10
11
12
13
14
5
7
9
11
5

5
7
9
11
5
7

Press any key to continue . . .


output with cout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
5
7
9
11
5

5
7
9
11
5
7

6Press any key to continue . . . //notice the 6 over there? 
@peter

jesus christ. i can't believe i forgot that. im so focused on this thing i forgot the basics. so bad. thanks. DX
Topic archived. No new replies allowed.