[英]Error 2146 in visual studio 2012 c++
I was using an older version of visual studio before and now I switched to visual studio 2012 and I'm getting an error in my code. 以前我使用的是Visual Studio的旧版本,现在切换到Visual Studio 2012,但是我的代码出现错误。 It says:
它说:
error C2146: syntax error : missing ')' before identifier 'r'
错误C2146:语法错误:标识符'r'之前缺少')'
How can I fix it...I've been looking for a solution for a very long time. 我该如何解决...很长一段时间以来,我一直在寻找解决方案。 The error is in the first line of the code...
错误在代码的第一行...
template <class T1, class T2> inline void va_copy(T1& r, const T2& v)
{
r[0] = v[0];
r[1] = v[1];
r[2] = v[2];
}
va_copy
is a macro defined in stdarg.h
and that's the reason why you're getting that error. va_copy
是在stdarg.h
定义的宏,这就是您收到该错误的原因。 You can prevent the preprocessor from expanding the macro by adding a pair of parenthesis ()
to the function name 您可以通过在函数名称中添加一对括号
()
来防止预处理器扩展宏。
#include <iostream>
#include <stdarg.h>
template <class T1, class T2> inline void (va_copy)(T1& r, const T2& v)
{
r[0] = v[0];
r[1] = v[1];
r[2] = v[2];
}
int main() {
int a[] = { 32, 33, 34 };
const int b[] = { 22, 23, 24 };
(va_copy)(a, b);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.