tags:

views:

117

answers:

3

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 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?

+10  A: 

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

Or you can use using namespace std at the top of your file, though since this looks like a header file, that's not recommended.

James McNellis
oops, thank you!
Jessica
You're welcome.
James McNellis
+3  A: 

You mean std::set.

alex tingle
+3  A: 

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
Klaim