C++ extern 函数错误:函数参数太多
我有一个 cw.h 文件,其中包含一堆外部函数,我想从我的 cw.cpp 文件中调用它们。
它们在 .h
中的表达方式如下。文件以及 Type
结构的声明(只是示例函数,不是函数的实际名称):
extern Type* new_type(), match(), sharetype();
但它们的定义和实现位于 cw.cpp
文件中。
每个函数都有 1 个或多个参数传递给它。
当我尝试编译时,我不断收到每个函数的错误消息:
cw.h:11: error: too many arguments to function Type new_type()
cw.cpp:575: error: at this point in file
我不知道如何修复它。我过去一小时一直在搜索(-_-)
编辑[已解决]:
我更改了 .h
文件中的代码,以匹配传递给函数的参数类型正在被召唤。 不再有错误。
I have a cw.h
file with a bunch of extern functions in it that I want to call from my cw.cpp
file.
They are expressed like this in the .h
. file along with the declarations of the Type
struct (just example functions, not the actual names of the functions):
extern Type* new_type(), match(), sharetype();
But their definitions and implementations are in the cw.cpp
file.
Each of the functions has 1 or more parameters passed into it.
When I try compiling, I keep getting this error message for each of the functions:
cw.h:11: error: too many arguments to function Type new_type()
cw.cpp:575: error: at this point in file
I have no idea how to fix it. And I've been searching for the past hour (-_-)
EDIT[SOLVED]:
I changed my code in the .h
file to match the types of the parameters being passed into the functions when they're being called.
No more errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 C++ 中,用
()
声明的函数是原型,意味着该函数不带参数。在 C++ 中,它相当于使用(void)
。它与 C 中的含义不同(即该函数采用未指定数量的参数)。In C++, a function declared with
()
is a prototype and means that the function takes no arguments. In C++ it is equivalent to using(void)
. It doesn't have the same meaning as in C (i.e. that the function takes an unspecified number of arguments).扩展 CharlesBailey 的答案:
在 C++ 中,由于重载,
Type* new_type()
与Type* new_type(int)
是不同的函数。您的参数需要与其定义相匹配:
Extending CharlesBailey's answer:
In C++,
Type* new_type()
is a different function thanType* new_type(int)
due to overloading.Your parameters need to match their definition: