在一个类中使用std::set?

3

我正在尝试结合使用std::set和一个类,就像这样:

#include <set>

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

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

但是,它不喜欢“set flags”部分。
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

据我所见,我给了一个 int 类型。你是否应该以不同的方式编写“设置变量”行,或者那里不允许这样做?

4
奖励分数给那些在评论中标明错误所在行的人。希望更多人这样做 :) - jalf
3个回答

10
你需要使用 std::setsetstd 命名空间中。

3

您需要使用std::命名空间(适用于所有STL / SL类)。

 std::set< int > myset;

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

3
你是指 std::set

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接