STL错误将VS 6项目转换为VS2010

STL Error Converting VS 6 Project to VS2010

本文关键字:转换 VS2010 项目 错误 VS STL      更新时间:2023-10-16

我正在将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

我可以单击"allocater_type"文本并按F12,IDE会将我带到列表中的"allocateR_type"定义。

如果我删除"::allocater_type",错误就会消失。

有什么想法会导致这种情况吗?

应该是

typedef typename std::list<T>::allocator_type AllocatorType;

您必须告诉编译器allocater_type实际上是一个类型。

顺便说一句,从STL容器继承并不是一个很好的做法,因为它们没有虚拟析构函数。

将typedef行修改为:

typedef typename std::list<T>::allocator_type AllocatorType;

以声明CCD_ 1是一种类型。