我正在将Visual Studio 6项目转换为Visual Studio 2010.该项目大量使用STL。 转换后,编译器会出错。代码和错误如下。
#include <list>
namespace mySpace
{
template <class T>
class MyList : public std::list<T>
{
public:
typedef std::list<T>::allocator_type AllocatorType;
}
错误: 错误2错误C2146:语法错误:缺少';'在标识符“AllocatorType”之前c:\ myProject \ mylist.h 39 1
我可以单击'allocator_type'文本并点击F12,IDE将我带到列表中的'allocator_type'定义。
如果删除':: allocator_type',错误就会消失。
任何想法会导致什么?
答案 0 :(得分:5)
应该是
typedef typename std::list<T>::allocator_type AllocatorType;
你必须告诉编译器allocator_type实际上是一个类型。
顺便说一句,继承STL容器并不是一个好习惯,因为它们没有虚拟析构函数。
答案 1 :(得分:1)
将typedef行修改为:
typedef typename std::list<T>::allocator_type AllocatorType;
说明std::list<T>::allocator
是一种类型。