简体   繁体   English

为什么 function 不能识别指针? [等候接听]

[英]Why does function not recognize pointer? [on hold]

Wrote a code to take in a string of words and remove the spaces from the end and start.编写了一个代码来接收一串单词并从末尾和开头删除空格。 Started the code with开始代码

void trim(char *source, char *new)

Visual Studio says missing ')' before 'new'. Visual Studio 在“新”之前说缺少“)”。 There are like 5 more errors, all stemming from this "new".还有 5 个错误,都源于这个“新”。 What could be causing this?这可能是什么原因造成的?

While this function signature is allowed in C, this will not work in C++ because new is a keyword in that language and can't be used as an identifier (such as the name of a parameter).虽然在 C 中允许使用此 function 签名,但这在 C++ 中不起作用,因为new是该语言中的关键字,不能用作标识符(参数名称)。

To solve this issue, make sure that you're compiling your C program as such, and not as a C++ program.要解决此问题,请确保您正在编译 C 程序,而不是 C++ 程序。 To get this code to run in C++, just rename the parameter.要让此代码在 C++ 中运行,只需重命名参数即可。

See here :这里

the identifiers that are keywords cannot be used for other purposes;作为关键字的标识符不能用于其他目的;

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

相关问题 为什么这段代码试图保存一个函数指针数组会返回一个错误? - Why does this code trying to hold an array of function pointer return an error? 程序无法识别智能指针 - the program does not recognize smart pointer 为什么期望引用的 function 与指针一起工作? - Why does a function expecting a reference work with a pointer? 函数为什么接受空指针? - Why does a function accept a void pointer? 为什么数组会衰减到模板函数中的指针 - why does the array decay to a pointer in a template function 为什么 cpp std::function 可以保存捕获 lambda,而 function 指针不能? - Why cpp std::function can hold capture-lambda, while function pointer cannot? 为什么这个模板 function 不能识别 lamda 的返回类型? - why this template function does not recognize the lamda's returned type? 即使未使用指向指针的指针作为参数来调用函数,为什么仍能正常工作? - Why does this work even though the function is not called with a pointer to a pointer as a parameter? 为什么指向 int 的指针转换为 void* 而指向函数的指针转换为 bool? - Why does pointer to int convert to void* but pointer to function convert to bool? std::function 不起作用,但普通的旧函数指针起作用 - 为什么? - std::function does not work, but plain old function pointer does - why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM