错误:')' 标记之前的预期主表达式 (C)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28262360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: expected primary-expression before ')' token (C)
提问by Flo
I am trying to call a function named characterSelection(SDL_Surface *screen, struct SelectionneNonSelectionne sel)
which returns a void
我正在尝试调用一个名为的函数characterSelection(SDL_Surface *screen, struct SelectionneNonSelectionne sel)
,它返回一个void
This is the .h
of the function I try to call:
这是.h
我尝试调用的函数:
struct SelectionneNonSelectionne;
void characterSelection(SDL_Surface *screen, struct SelectionneNonSelectionne);
void resetSelection(SDL_Surface *screen, struct SelectionneNonSelectionne);
On my main function, I try to call it like this:
在我的主函数中,我尝试这样称呼它:
characterSelection(screen, SelectionneNonSelectionne);
When I compile, I have the message:
当我编译时,我收到以下消息:
error: expected primary-expression before ')' token
I made the includes
. I suppose I miscall the second argument, my struct
. But, I can't find why on the net.
我做了includes
. 我想我错误地调用了第二个参数,我的struct
. 但是,我在网上找不到原因。
Have you got any idea about what I did wrong ?
你知道我做错了什么吗?
回答by ninja
You should create a variable of the type SelectionneNonSelectionne.
您应该创建一个 SelectionneNonSelectionne 类型的变量。
struct SelectionneNonSelectionne var;
After that pass that variable to the function like
之后将该变量传递给函数,如
characterSelection(screen, var);
The error is caused since you are passing the type name SelectionneNonSelectionne
错误是因为您传递了类型名称 SelectionneNonSelectionne
回答by juanchopanza
A function call needs to be performed with objects. You are doing the equivalent of this:
需要对对象执行函数调用。你正在做的相当于:
// function declaration/definition
void foo(int) {}
// function call
foo(int); // wat!??
i.e. passing a type where an object is required. This makes no sense in C or C++. You need to be doing
即传递需要对象的类型。这在 C 或 C++ 中没有意义。你需要做
int i = 42;
foo(i);
or
或者
foo(42);
回答by ForceBru
You're passing a type as an argument, not an object. You need to do characterSelection(screen, test);
where test is of type SelectionneNonSelectionne
.
您将类型作为参数传递,而不是对象。你需要characterSelection(screen, test);
在 test 类型的地方做SelectionneNonSelectionne
。