Ste*_*ber 2 c++ stl visual-studio
我正在将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;
}
Run Code Online (Sandbox Code Playgroud)
错误:错误2错误C2146:语法错误:缺少';' 在标识符'AllocatorType'c:\ myProject\mylist.h之前39 1
我可以单击'allocator_type'文本并按F12,IDE将我带到列表中的'allocator_type'定义.
如果我删除':: allocator_type',错误就会消失.
任何想法会导致什么?
它应该是
typedef typename std::list<T>::allocator_type AllocatorType;
Run Code Online (Sandbox Code Playgroud)
你必须告诉编译器allocator_type实际上是一个类型.
顺便说一下,继承STL容器并不是一个很好的做法,因为它们没有虚拟析构函数.
| 归档时间: |
|
| 查看次数: |
254 次 |
| 最近记录: |