Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C2975';的模板参数无效;N';,应为编译时常量表达式_C++_Templates_Visual C++_Compiler Errors - Fatal编程技术网

C++ C2975';的模板参数无效;N';,应为编译时常量表达式

C++ C2975';的模板参数无效;N';,应为编译时常量表达式,c++,templates,visual-c++,compiler-errors,C++,Templates,Visual C++,Compiler Errors,下面是一种应该在7.1版(VS2003)上运行的代码片段 我无法在Visual Studio 2013上编译它 .h header: template <HINSTANCE h, DWORD hash, class N> inline LPVOID testFunc(N n1) { ... return ret_func(n1); } .cpp: HINSTANCE kernel32; int WINAPI WinMain(...) { ...

下面是一种应该在7.1版(VS2003)上运行的代码片段

我无法在Visual Studio 2013上编译它

.h header:

template <HINSTANCE h, DWORD hash, class N>
inline LPVOID testFunc(N n1)
{   
    ...
    return ret_func(n1);
}


.cpp:

HINSTANCE kernel32;

int WINAPI WinMain(...)
{
    ...
    kernel32 = GetKernel32();  
    HINSTANCE mod = testFunc<kernel32, 0x0BADC0DE>("some_string");  // C2975
    ...
}
.h标题:
模板
内联LPVOID testFunc(N n1)
{   
...
返回ret_func(n1);
}
.cpp:
内核32;
int WINAPI WinMain(…)
{
...
kernel32=GetKernel32();
HINSTANCE mod=testFunc(“某些字符串”);//C2975
...
}
错误C2975:“h”:testFunc的模板参数无效,应为编译时常量表达式

我试着这样做:

HINSTANCE kernel32 = GetKernel32();  // implemented ok
HINSTANCE mod = testFunc<kernel32, 0x0BADC0DE>("some_string");  // C2971
HINSTANCE kernel32=GetKernel32();//实施ok
HINSTANCE mod=testFunc(“某些字符串”);//C2971

错误C2971:'pushargEx':模板参数'h':'kernel32':局部变量不能用作非类型参数

kernel32不是编译时常量。这是必须的

kernel32不是编译时常量。这是必须的

错误实际上是不言自明的:

应为编译时常量表达式

哪个
kernel32
不是


“编译时间常数”意味着编译时必须知道该值,即。E在源代码本身中指定(直接或间接)。

错误实际上是不言自明的:

应为编译时常量表达式

哪个
kernel32
不是


“编译时间常数”意味着编译时必须知道该值,即。E(直接或间接地)在源代码本身中指定。

“some_string”是一个
const char[]
,而不是一个类。在这个上下文中,类的意思是“some type”而不是正常意义上的类。@Wimmel怎么办?它有一个类型。@Wimmel:no,
class
是可以的,它相当于
typename
。非类型参数类型必须是整型或指针型,更不用说其他错误了
“some_string”
是一个
常量字符[]
,而不是一个类。在这个上下文中,类的意思是“some type”而不是正常意义上的类。@Wimmel是这样吗?它有一个类型。@Wimmel:no,
class
可以,它相当于
typename
。非类型参数类型必须是整型或指针型,更不用说其他错误了