C ++ extern函数错误:函数参数过多 [英] C++ extern function error: too many arguments to function
问题描述
我有一个cw.h
文件,其中有一堆extern函数,我想从我的cw.cpp
文件中调用.
I have a cw.h
file with a bunch of extern functions in it that I want to call from my cw.cpp
file.
它们在.h
中这样表达.文件以及Type
结构的声明(只是示例函数,而不是函数的实际名称):
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();
但是它们的定义和实现在cw.cpp
文件中.
每个函数都有一个或多个传递给它的参数.
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 (-_-)
编辑[已解决]:
我更改了.h
文件中的代码,以匹配在调用函数时传递给函数的参数类型.
没有更多错误.
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.
推荐答案
在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).
这篇关于C ++ extern函数错误:函数参数过多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!