Classes SOS

Alrite, I need help in outputting a set of strings/names using classes

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
 #include <iostream>
using namespace std;

class Menu {
   
   public:
   
   void PrintNames ()
   {
        cout<<"Brian";
        cout<<"Hector";
        cout<<"Lucy";
   }
   
   
};


int main () 
{
  
  Item menu;
  menu;

  system("pause");
  return 0;
}


But nothing seems to happen, any hints?
Thanks.
Well, for one you did not create a class by the name of Item, but that of Menu. Two, menu is not a function- it is the object. To call the function inside of the class, you must specify:

menu.PrintNames();
Last edited on
closed account (zb0S216C)
Of course nothing is happening, you're not telling the program to do anything. In order to actually get some printing done, you need to call "Menu::PrintNames( )". Of course, functions don't call themselves.

1
2
3
4
5
6
7
int main () 
{
  
  Item menu;
  menu.PrintNames( ); // Here
  // ...
}

Wazzak
Last edited on
Thank You very much Mr.Ispil
May you and your computer be blessed.
Topic archived. No new replies allowed.