T.T*_*.T. 2 c c++ variables pointers function
我想将我在另一个程序中找到的C函数复制并粘贴到我的C++程序中.
其中一个函数参数使用"this"指针.
void cfunction( FILE *outfilefd, const VARTYPEDEFINED this);
Run Code Online (Sandbox Code Playgroud)
这里的C++编译器错误在函数原型上:
error C2143: syntax error : missing ')' before 'this'
Run Code Online (Sandbox Code Playgroud)
如何使这个C++可用?
谢谢.
编辑(根据Betamoo评论)
void cfunction( FILE *outfilefd, const VARTYPEDEFINED this);
{
UINT8 temp = 0;
temp = (UINT8)( this & 0x000000FF );
if ( ( temp > LIMIT ) )
......
else
{
......
}
}
Run Code Online (Sandbox Code Playgroud)
你有两个选择.您可以将代码保留为C,只需创建一个C++标头,以便从C++调用该C代码:
#ifdef __cplusplus
extern "C" {
#endif
void cfunction(FILE *, const VAR);
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
或者你可以重写该函数足以让它以C++编译(可能只是将其this
参数重命名为其他类似的东西thisvar
).
重命名this
为其他内容.C没有特殊this
变量,它只是一个变量,就像任何其他变量一样.