template<class T>
class myset
{
public:
bool member(const T &item) const;
void insert(const T &item);
void remove(const T &item);
int cardinality() const;
if (int_set.member(2))
printf("2 is the member of int_set\n");
else
printf("2 is not the member of int_set\n");
printf("the cardinality of int_set is %d\n", int_set.cardinality());
int_set.remove(3);
printf("the cardinality of int_set is %d\n", int_set.cardinality());
return 0;
}
上面這段代碼使用g++編譯后,產(chǎn)生如下錯誤信息:
[lej@localhost test_cpp]$ g++ item_40.cpp -o item_40
item_40.cpp: In member function ‘void myset<T>::remove(const T&)’:
item_40.cpp:35: 錯誤:expected `;' before ‘it’
item_40.cpp:36: 錯誤:‘it’在此作用域中尚未聲明
item_40.cpp: In member function ‘void myset<T>::remove(const T&) [with T = int]’:
item_40.cpp:61: instantiated from here
item_40.cpp:35: 錯誤:依賴名‘std::list::iterator’被解析為非類型,但實例化卻產(chǎn)生了一個類型
item_40.cpp:35: 附注:如果您想指定類型,請使用‘typename std::list::iterator’
[lej@localhost test_cpp]$