ISO C++ forbids declaration of 'iterator' with no type

1288 ワード

xcode下コンパイルエラー:ISO C++forbids declaration of'iterator'with no type
エラーポイント:
template<class T>

class MyVector: public std::vector<T>

{

public:

	typedef std::vector<T> vecType;

	typedef vecType::iterator vecIterator; //  



	MyVector(){};

	MyVector(const vecType& _vec);

	//.......

	//.......

};

他の人の回答によると、http://stackoverflow.com/questions/1732895/error-iso-c-forbids-declaration-of-iterator-with-no-type.原因を特定:
“The reason being being that iterator is dependent on what T is, so the compiler can't be sure it's a typename unless you tell it.”
typenameを追加し、修正後にコンパイルします.
template<class T>

class MyVector: public std::vector<T>

{

public:

	typedef std::vector<T> vecType;

	typedef typename vecType::iterator vecIterator; //typename



	MyVector(){};

	MyVector(const vecType& _vec);

	//.......

	//.......

};

mark! もう一つ「C++コンパイラはテンプレートの分離コンパイルをサポートできません」、why?google.....