相关疑难解决方法(0)

具有依赖范围的嵌套模板

什么是依赖范围以及在以下错误的上下文中typename的含义是什么?

$ make
g++ -std=gnu++0x main.cpp
main.cpp:18:10: error: need 'typename' before 'ptrModel<std::vector<Data> >::Type' because 'ptrModel<std::vector<Data> >' is a dependent scope
make: *** [all] Error 1


/*
 * main.cpp
 */

#include <vector>
#include <memory>

template<typename T>
struct ptrModel
{
 typedef std::unique_ptr<T> Type;
};


template<typename Data>
struct ptrType
{
 typedef ptrModel< std::vector<Data> >::Type Type;
};

int main()
{
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ templates scope nested

79
推荐指数
1
解决办法
4万
查看次数

标签 统计

c++ ×1

nested ×1

scope ×1

templates ×1