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

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

原文地址:https://www.cnblogs.com/fjut/p/2950634.html