Qt:"Expected type-specifier"出现在一台设备上,而不是另一台具有相同代码的设备上
Qt: "Expected type-specifier" appearing on one device and not another with same code
我和一位朋友是C++和Qt的初学者。我们正在一起开发一个Qt项目(直升机游戏),当她向我发送她在计算机上的代码时,该代码运行没有错误,它在一行上给出了"预期的类型说明符"错误,该行将指针设置为等于我们的"游戏"构造函数的新实例。代码有问题还是与我的计算机有关?
这就是我们的错误出现在主函数中的地方:
#include <QApplication>
#include <QGraphicsItem>
#include <QGraphicsPixmapItem>
#include <QGraphicsView>
#include <QGraphicsScene>
//including for splash screen
#include <QSplashScreen>
#include <QTimer>
//our header files
#include "player.h"
#include "game.h"
game * heli_game;
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QSplashScreen * splash = new QSplashScreen;
splash->setPixmap(QPixmap(":/images/splash.png"));
splash->show();
game * heli_game;
heli_game = new game::game(); //ERROR HERE: "expected type-specifier"
QTimer::singleShot(2500, splash, SLOT(close()));
return a.exec();
}
这是我们的游戏头文件,其中定义了构造函数:
#ifndef GAME
#define GAME
#include <QGraphicsView>
#include <QWidget>
#include <QGraphicsScene>
#include "player.h"
#include "score.h"
//#include "game_over.h"
class game: public QGraphicsView{
Q_OBJECT
public:
//constructors
game(QWidget* parent=NULL);
//public attributes
QGraphicsScene * scene;
player * copter;
score * Score;
// game_over * game_over;
};
#endif // GAME
new game::game();
^ 仅当game
类位于名为 game
的命名空间中时,这才有意义。 由于不是,编译器无法知道您指的是哪种类型。
您可能打算这样做:
new game();
我还应该指出,heli_game
在您的主文件中声明了两次。
heli_game = new game::game();
不正确,应该是
heli_game = new game();
只。您的代码不应使用任何编译器进行编译。
顺便说一下,你有一个"heli_game *game"全局变量和另一个在main()中。
相关文章:
- 有没有一种代码密度较低的方法来使用非默认构造函数初始化数组?
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作
- 在另一台 PC 上执行程序时加载 SDL2 共享库时出错
- 如何为一段代码启用 -permissive
- 谷歌基准测试,如何只调用一次代码?
- 注释一行使代码工作,而没有它,代码不起作用
- 使用Qt Creator在调试模式下编译一段代码
- 另一台电脑上的Visual Studio C++项目无法生成
- Homebrew OS X OpenCV - 在另一台Mac上运行时寻找dylib
- 当我在结构中包含多个数组时,我的程序会跳过一堆代码
- 当我在支持 avx2 的机器上编译并在另一台仅支持 avx 的机器上运行二进制文件时会发生什么?
- 防止一段代码在协程中并发执行
- 块内的 #defining 真的是一种代码气味吗?
- 如何在另一台未安装 Visual Studio 的计算机中使用由 Visual Studio 生成的 dll
- 在另一台计算机中运行 GTKMM 代码时未定义的符号
- Qt:"Expected type-specifier"出现在一台设备上,而不是另一台具有相同代码的设备上
- OpenCl代码在一台机器上工作,但我在另一台机器中得到了CL_INVALID_KERNEL_ARGS
- OpenGL代码在一台计算机上运行缓慢(但在其他计算机上则不然)
- 如何从c++代码在另一台计算机上运行程序
- 用c++代码在一台Linux机器上出现分段错误,而在另一台机器上没有