错误:')'令牌之前的预期primary-expression(C)

Flo*_*Flo 15 c c++ compiler-errors procedure function

我想打电话给一个名为函数characterSelection(SDL_Surface *screen, struct SelectionneNonSelectionne sel)返回一个void

这是.h我试图调用的函数:

struct SelectionneNonSelectionne;
void characterSelection(SDL_Surface *screen, struct SelectionneNonSelectionne);
void resetSelection(SDL_Surface *screen, struct SelectionneNonSelectionne);
Run Code Online (Sandbox Code Playgroud)

在我的主要功能上,我试着像这样调用它:

characterSelection(screen, SelectionneNonSelectionne);
Run Code Online (Sandbox Code Playgroud)

编译时,我收到消息:

 error: expected primary-expression before ')' token
Run Code Online (Sandbox Code Playgroud)

我做了includes.我想我错误地呼了第二个论点,我的struct.但是,我无法在网上找到原因.

你知道我做错了什么吗?

小智 23

您应该创建一个SelectionneNonSelectionne类型的变量.

struct SelectionneNonSelectionne var;
Run Code Online (Sandbox Code Playgroud)

之后将该变量传递给函数之类的

characterSelection(screen, var);
Run Code Online (Sandbox Code Playgroud)

由于您传递的是类型名称SelectionneNonSelectionne,因此会导致该错误


jua*_*nza 5

需要对对象执行函数调用。你正在做的相当于:

// function declaration/definition
void foo(int) {}

// function call
foo(int); // wat!??
Run Code Online (Sandbox Code Playgroud)

即传递需要对象的类型。这在 C 或 C++ 中没有意义。你需要做

int i = 42;
foo(i);
Run Code Online (Sandbox Code Playgroud)

或者

foo(42);
Run Code Online (Sandbox Code Playgroud)