简体   繁体   English

如何使用具有(this)作为变量名的.h文件到CPP文件中

[英]How to use .h file which have (this) as variable name into CPP file

I have a header my.h which have following declaration of a function named as my_func.我有一个 header my.h,它声明了一个名为 my_func 的 function。

#pragma once
void my_func (int *this);

this function is implemented in my.c这个 function 在 my.c 中实现

void my_func (int *this)
{
  printf("%d", *this);
}

in foo.cpp i want to use my_func在 foo.cpp 我想使用 my_func

extern "C"
{
    #include <foo.h>
}

but i am getting following error error: expected ')' void my_func (int *this);但我收到以下错误错误:预期')' void my_func (int *this); Actually in my project this used/manipulated in.C/.h files many place.实际上,在我的项目中,这个使用/操作的 in.C/.h 文件很多地方。 this is used as variable in those header/.c files many place.在许多地方用作那些 header/.c 文件中的变量。 I just took the above example for simplicity purpose to describe the compile error i am facing.为了简单起见,我只是举了上面的例子来描述我面临的编译错误。

this is a keyword in c++. this是 c++ 中的关键字 You cannot use it as a variable.您不能将其用作变量。 You can simply rename it to something else in the header.您可以简单地将其重命名为 header 中的其他名称。

In fact, you can even remove the variable name completely.事实上,您甚至可以完全删除变量名。 The compiler won't care.编译器不会在意。 Named arguments are there to tell developers what the argument is meant to represent.命名为 arguments 的目的是告诉开发人员该参数的含义。 It does not inform the compiler of anything.它不会通知编译器任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM