Using std :: set in a class?

I am trying to combine using std :: set and a class, for example:

#include <set>

class cmdline
{
    public:
        cmdline();
        ~cmdline();

    private:
        set<int> flags; // this is line 14
};

but he does not like the flags set; part:

cmdline.hpp:14: error: ISO C++ forbids declaration of 'set' with no type
cmdline.hpp:14: error: expected ';' before '<' token
make: *** [cmdline.o] Error 1

As far as I can see, I gave the type (from int). Do you write the string "set variable" in different ways or is it not allowed there?

+3
source share
3 answers

You need to use std::set; setis in the namespace std.

+10
source

You mean std::set.

+3
source

You must use the std :: namespace (for all STL / SL classes).

 std::set< int > myset;

or

 using namespace std; // don't do this in a header - prefer using this in a function code only if necessary
+3
source

Source: https://habr.com/ru/post/1720232/


All Articles