2009-10-15 59 views
3

我試圖用一個std ::集和一類結合起來,就像這樣:在類中使用std :: set?

#include <set> 

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

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

,但它不喜歡的標誌集;部分:

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)的一個類型。你是不是寫了「set variable」行,還是不允許?

+4

與評論實際上標誌着獎勵積分哪一行的錯誤指。希望更多人做到這一點:) – jalf 2009-10-15 22:23:36

回答

10

您需要使用std::set; set位於std命名空間中。

+0

哎呀,謝謝! – Jessica 2009-10-15 21:39:31

+0

不客氣。 – 2009-10-15 21:49:23

3

您的意思是std::set

3

您必須使用std :: namespace(對於所有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