游戏文件中包含的该.h文件无法识别变量和“在范围内”的函数:
#ifndef GAME_H
#define GAME_H
#include <iostream>
using namespace std;
#include "SDL2/SDL.h"
class Igra
{
private:
SDL_Renderer *obl;
SDL_Window *okno;
bool traja;
Uint32 Takt_zac;
public:
Igra();
~Igra();
void zanka();
void posodobi();
void vnos();
void oblikuj();
};
#endif // GAME_H
我制作的game.cpp:
#include "game.h"
#define fps 60
Igra::Igra()
{
SDL_Init(0);
SDL_CreateWindowAndRenderer(360,240,0,&win,&ren);
SDL_SetWindowTitle(win,"Planet Saver");
traja=true;
void loop();
}
Igra::~Igra()
{
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
}
void Igra::zanka()
{
while(Igra::traja)
{
Takt_zac=SDL_GetTicks();
void kon30(Uint32 Takt_zac);
oblikuj();
vnos();
posodobi();
}
}
void kon30(Uint32 Takt_zac)
{
if((1000/fps)>SDL_GetTicks()-Takt_zac)
SDL_Delay(1000/fps-(SDL_GetTicks()-Takt_zac));
}
void Igra::oblikuj()
{
}
void Igra::vnos()
{
}
void Igra::posodobi()
{
}
编译器产生的错误:
||=== Build: Debug in g0.1 (compiler: GNU GCC Compiler) ===|
G:\SDL+igra\g0.1\game.cpp||In constructor 'Igra::Igra()':|
G:\SDL+igra\g0.1\game.cpp|10|error: 'traja' was not declared in this scope|
G:\SDL+igra\g0.1\game.cpp||In member function 'void Igra::zanka()':|
G:\SDL+igra\g0.1\game.cpp|23|error: 'traja' is not a member of 'Igra'|
G:\SDL+igra\g0.1\game.cpp|25|error: 'Takt_zac' was not declared in this scope|
G:\SDL+igra\g0.1\game.cpp|27|error: 'oblikuj' was not declared in this scope|
G:\SDL+igra\g0.1\game.cpp|38|error: no 'void Igra::oblikuj()' member function declared in class 'Igra'|
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|