简体   繁体   English

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

[英]STL Error Converting VS 6 Project to VS2010

I'm converting a Visual Studio 6 project to Visual Studio 2010. The project uses STL heavily. 我正在将Visual Studio 6项目转换为Visual Studio2010。该项目大量使用STL。 After converting, the compiler gives an error. 转换后,编译器给出错误。 The code and error are as follows. 代码和错误如下。

#include <list>

namespace mySpace
{

template <class T>
class MyList : public std::list<T>
{
    public:
        typedef std::list<T>::allocator_type AllocatorType;
    }

Error: Error 2 error C2146: syntax error : missing ';' 错误:错误2错误C2146:语法错误:缺少';' before identifier 'AllocatorType' c:\\myProject\\mylist.h 39 1 在标识符'AllocatorType'之前c:\\ myProject \\ mylist.h 39 1

I can click on the 'allocator_type' text and hit F12 and the IDE takes me to the 'allocator_type' definition in list. 我可以单击“ allocator_type”文本并单击F12,IDE会将我带到列表中的“ allocator_type”定义。

If I remove '::allocator_type' the error goes away. 如果我删除':: allocator_type',错误将消失。

Any ideas what would cause this? 有什么想法会导致这种情况吗?

It should be 它应该是

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

You have to tell the compiler allocator_type is actually a type. 您必须告诉编译器allocator_type实际上是一种类型。

By the way, inheriting from STL containers isn't a great practice as they don't have virtual destructors. 顺便说一句,从STL容器继承不是一个好习惯,因为它们没有虚拟析构函数。

Modify the typedef line as: 将typedef行修改为:

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

to state that std::list<T>::allocator is a type. 说明std::list<T>::allocator是一种类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM