I can't use the enum from my class

I have been trying to use my exit_back enum and I can't seem to do it. What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//main.cpp
#include <iostream>
#include <string>
#include "Guest.h"
#include "MenuCreator.h"

int main()
{
    MenuCreator test;
    test.addtitle("The title");
    test.add("Option 1");
    test.add("Option 2");
    test.add(exit, 'e'); // error: 'exit' was not declared in this scope|
    test.add(back,'b'); // error: 'back' was not declared in this scope|
    test.display();

    return 0;
}


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
MenuCreator.h
#ifndef MENUCREATOR_H
#define MENUCREATOR_H

#include <string>
#include <vector>

using namespace std;

class MenuCreator
{
public:
    MenuCreator();
    virtual ~MenuCreator();
    void add(string description); //1. description
    enum exit_back {exit, back};
    void add(exit_back val, char exit_back_char);
    void addtitle(string t);
    void display();
protected:
private:
    vector<string> menu_vector;
    bool exitTF;
    bool backTF;
    char exit_back_char;
    string title;
    exit_back eb;
};

#endif // MENUCREATOR_H 


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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
////MenuCreator.cpp
#include "MenuCreator.h"
#include <iostream>
#include <string>
#include <vector>
#include <cctype>

using namespace std;

MenuCreator::MenuCreator()
{
    //ctor
}

MenuCreator::~MenuCreator()
{
    //dtor
}

void MenuCreator::add(string description) //1. description
{
    menu_vector.push_back(description);
}
void MenuCreator::add(exit_back val, char exit_back_char) //E(x)it...
{
    if(val == exit)
    {
        exitTF = true;
        backTF = false;
    }
    if(val == back)
    {
        backTF = true;
        exitTF = false;
    }
    exit_back_char = exit_back_char;
}
void MenuCreator::addtitle(string t)
{
    title = t;
}
void MenuCreator::display()
{
    cout << title << endl;
    unsigned int i = 0;
    while(i < title.length())
    {
        cout << "=";
        ++i;
        }
        cout << endl << endl;
    //iterate through menu_vector
    for (vector<string>::iterator menu_item = menu_vector.begin();
            menu_item != menu_vector.end();
            ++menu_item)
    {
        //cout each menu item that was added to the menu
        cout << *menu_item << endl;
    }
    cout << endl;
    if(backTF) //Is there is a back menu item added?
    {
        cout << "...press " << exit_back_char << "to go back to the previous menu";
        if(isalpha(exit_back_char))
        {
            if(isupper(exit_back_char))
            {
                exit_back_char = tolower(exit_back_char);
            }
        }
    }
    if(exitTF) //Is there an exit menu item added? Cout exit ,emu item last
    {
        cout << "...press " << exit_back_char << " to exit";
        if (isalpha(exit_back_char)) //is exit_back_char alpha?
        {
            if(isupper(exit_back_char)) //is exit_back_char upperase alpha?
            {
                //if exit_back_char is an uppercase alpha, make exit_back_char lowercase
                exit_back_char = tolower(exit_back_char);
            }
        }
    }
        cout << "\n"; //Prevent clustering of cout output
}


EDIT:
Nevermind. I have to use:
1
2
    test.add(MenuCreator::exit, 'e');
    test.add(MenuCreator::back, 'b');
Last edited on
Topic archived. No new replies allowed.