STL将VS 6项目转换为VS2010时出错 [英] STL Error Converting VS 6 Project to VS2010
问题描述
我将Visual Studio 6项目转换为Visual Studio 2010.该项目大量使用STL。
转换后,编译器给出一个错误。代码和错误如下。
#include< list>
命名空间mySpace
{
模板< class T>
class MyList:public std :: list< T>
{
public:
typedef std :: list< T> :: allocator_type AllocatorType;
}
错误:
错误2错误C2146:语法错误: ;'before identifier'AllocatorType'c:\myProject\mylist.h 39 1
我可以点击'allocator_type'文本并点击F12,
如果我删除':: allocator_type',错误消失。
任何想法会导致什么?
应该是
typedef typename std :: list< T> :: allocator_type AllocatorType;
你必须告诉编译器allocator_type实际上是一个类型。
顺便说一句,继承STL容器不是一个伟大的做法,因为他们没有虚拟析构函数。
I'm converting a Visual Studio 6 project to Visual Studio 2010. The project uses STL heavily. 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 ';' before identifier '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.
If I remove '::allocator_type' the error goes away.
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.
By the way, inheriting from STL containers isn't a great practice as they don't have virtual destructors.
这篇关于STL将VS 6项目转换为VS2010时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!