C++令牌之前'('预期的构造函数、析构函数或类型转换
C++ expected constructor, destructor, or type conversion before '(' token
我知道你可能会认为这篇文章是另一篇重复文章,但事实并非如此。它不是重复的,因为我的代码与其他代码不同,而且没有人的帖子(我见过)解决了我的问题。
这是我的代码:
#include "sprite.h"
SDL_Surface * SPRITE::screen;
int player;
void DrawPlayer(int x, int y) {
SDL_Rect rect = {x,y,20,20};
SDL_FillRect(SPRITE::screen, &rect, 0x00CC00);
}
DrawPlayer(20,20);
错误在DrawPlayer(20,20);
行
您没有从任何函数中调用DrawPlayer()
。
不能在任何方法之外调用DrawPlayer
。调用必须在类方法或全局方法内部。
Try this:
#include "sprite.h"
SDL_Surface * SPRITE::screen;
int player;
void DrawPlayer(int x, int y) {
SDL_Rect rect = {x,y,20,20};
SDL_FillRect(SPRITE::screen, &rect, 0x00CC00);
}
int main()
{
DrawPlayer(20,20);
return 0;
}
DrawPlayer
需要在main
或其他函数中。
当不在函数体中时,如何调用函数?
相关文章:
- 构造函数和转换运算符之间的重载解析
- C++无效的函数类型转换
- 元组尺寸默认构造函数及其转换为std :: size_t
- C++ 03 类模板 这是转换构造函数还是转换运算符?以及如何声明解决此问题的方法
- 是否可以将一种函数类型转换为另一种采用相同参数但返回类型不同的函数类型
- 调用构造函数或转换
- 需要构造函数/析构函数/类型转换错误
- 使用构造函数自动转换
- static_cast转换构造函数与转换运算符
- 构造函数和转换
- C++ - 打印地图<结构,结构,构造函数>类型
- 错误:从"<未解析的重载函数类型>"转换为非标量类型
- 有没有一种干净的方法可以将 C# 'params object[]' 构造函数参数转换为C++构造函数?
- 混淆了复制构造函数和转换构造函数
- C++11:在按值传递参数初始化时转换构造函数和转换函数之间的歧义
- 继承构造函数+非默认构造函数类型的类内初始化失败
- 特征日志和exp函数类型转换错误
- c++ python构造函数类型错误(可能的命名空间问题)
- 构造函数的转换不适用于运算符重载
- 具有构造函数类型转换和转换操作符的转换序列