Class function call fail

Hi guys.
I'm trying to class a function from a class. But, there's an error and i can't find it. Can you please help me find what is wrong with the way i'm calling the function. I commented on the error, it's in the main function at case 2. Please help. Thank you very much.

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
56
57
58
59
60
61
62
#include <iostream>
#include <string>
using namespace std;

class message
{
public:
	message()
	{
		numberOfInbox=0;
		numberOfAddress=0;
		numberOfOutbox=0;
	}

	void inbox(int temp){
		cout << "From : " << addres[temp] << endl;
		cout << " Meesage : \n" << inbox[temp] << endl << endl;
	}
	int getNumberOfInbox(){
		return numberOfInbox;
	}

protected:
	string inbox[1000];
	int numberOfInbox;
	string addres[1000];
	int numberOfAddress;
	string outbox[1000];
	int numberOfOutbox;
};

int main()
{
	message object;
	int choose,a=0;

	do{
		do{
			cout << " Message\n";
			cout << " 1. New\n";
			cout << " 2. Inbox\n";
			cout << " 3. Outbox\n";
			cout << " 4. Exit\n";
		}while(choose<1||choose>4);
		switch(choose)
		{
		case 1:

			break;
		case 2:
			for(a=0;a<object.getNumberOfInbox();a++){
				object.inbox(a);   // why this don't work????
			}
			cin.get();
			break;
		case 3:
			break;
		}
	}while(choose!=4);

	return 0;
}
Last edited on
After i change object.inbox(a) to object.getInbox(a), it works fine. But still I don't understand why? If you understand, please explain. Thank you.
Your default constructor sets numberOfInbox to zero. Consequently, in the for loop on line 51 in the condition a<object.getNumberOfInbox() a=0 and object.getNumberOfInbox()=0 so the condition is false at the very beginning of the loop and hence the loop is never executed at all.
Thank you for you explanation.
Topic archived. No new replies allowed.