Using a std::set in a class?
I am trying to combine using a std::set and a class, like this:
#include <set>
class cmdline
{
public:
cmdline();
~cmdline();
private:
set<int> flags; // this is line 14
};
but, it doesn't like the set flags; part:
cmdline.hpp:14: error: ISO C++ forbids declaration of 'set' with no开发者_StackOverflow type
cmdline.hpp:14: error: expected ';' before '<' token
make: *** [cmdline.o] Error 1
As far as I can see, I gave a type (of int). Do you write the "set variable" line differently, or is it not allowed there?
You need to use std::set
; set
is in the std
namespace.
You mean std::set
.
You have to 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
精彩评论