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 won't work????
			}
			cin.get();
			break;
		case 3:
			break;
		}
	}while(choose!=4);

	return 0;
}
closed account (1vRz3TCk)
The names of your member data should not be the same as your member functions.

try something like:
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
class message
{
public:
    message()
    {
        m_numberOfInbox=0;
        m_numberOfAddress=0;
        m_numberOfOutbox=0;
    }

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

protected:
    string  m_inbox[1000];
    int     m_numberOfInbox;
    string  m_addres[1000];
    int     m_numberOfAddress;
    string  m_outbox[1000];
    int     m_numberOfOutbox;
};
Last edited on
message()
{
numberOfInbox=0;
numberOfAddress=0;
numberOfOutbox=0;
}

You just made "numberOfInbox=0".

What value else do you want this function: "getNumberOfInbox()" gives you?
Topic archived. No new replies allowed.