我有一个帮助函数创建一个Array_Refobj.该函数有一个参数,vector<t>- 编译器正在抱怨.我正在使用VS2010.
.h.Array_Ref.h.cpp文件中.typename在front of vector<T>typedef typename前面vector<T>似乎没什么用.
#include <vector>
template<class T>
Array_Ref<T> make_ref(vector<T> &v, int s)
{
return (v.size()) ? Array_Ref<T>(v,s): Array_Ref<T>(0,0);
}
Run Code Online (Sandbox Code Playgroud)
我越来越:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed.
error C2988: unrecognizable template declaration/definition
error C2059: syntax error : '<'
Run Code Online (Sandbox Code Playgroud)
但是,将它放在相同的头文件中Array_Ref.h工作正常:
template<class T,int size>
Array_Ref<T> make_ref(T (&p)[size])
{
return (p) ? Array_Ref<T>(p,size): Array_Ref<T>(0,0);
}
Run Code Online (Sandbox Code Playgroud)