can't get input from a function called within a class

So I have a class that displays a menu in the terminal and takes input and executes a function
1
2
3
4
5
6
7
class interface {
    interface();
    menu();
    select(int);
    ...
    intput();
}


The menu function is a list of options that calls the select function after an option number has been inputted. The select function is a bunch of if statements that executes the classes functions depending on the integer sent to it.
1
2
3
4
5
6
7
8
9
10
11
12
13
void menu()
{
  //menu items
  cin >> option;
  select(option);
}

void select(int o)
{
  //bunch of if statements
  if(o == some number)
    input();
}


my input function looks like:

1
2
3
4
5
6
7
input()
{
  string s;
  cin.clear();
  getline(cin, s);
  cout << "Input is: " << s << endl;
}


I create an interface object in main, call menu, select input, and it runs the function without taking input.

Then I access the input function from the object

1
2
3
4
5
6
7
8
9
10
main()
{
  Interface I;

  // accessing the input function from the menu
  // won't take input & the function still executes
  I.menu(); 

  I.input(); // takes input
}


When I run input from the menu, it never takes input it just does the output with nothing. And when I run it directly from main, it takes input and outputs everything correctly.
Last edited on
A contents of a class are private by default. You need to declare the public parts as public.
Topic archived. No new replies allowed.