У меня есть код: loading* loadingScreen = new loading(device);
Когда я компилирую программу, компилятор жалуется, что экран загрузки не был объявлен:
error: 'loadingScreen' was not declared in this scope
loading* loadingScreen = new loading(device);
^
Я не уверен, что это вызывает. Что я пробовал:
Вот мой файл main.cpp:
#include <iostream>
#include <irrlicht.h>
#include <future> // std::async, std::future
#include <chrono> // Millisecond timer
#include <pthread.h>
#include <loading.h>
#include <fps.h>
bool loading = false;
struct load_struct {
irr::IrrlichtDevice *device;
fps *fpsLevel;
};
void load(void * loadingStruct)
{
loading = true;
struct load_struct *args = (struct load_struct *) loadingStruct;
loading = false;
pthread_exit(NULL);
}
int main()
{
//Create display to optimal settings.
irr::IrrlichtDevice *device = irr::createDevice(irr::video::EDT_NULL);
irr::s32 depth = device->getVideoModeList()->getDesktopDepth();
irr::core::dimension2d<irr::u32> resolution = device->getVideoModeList()->getDesktopResolution();
device->drop();
device = irr::createDevice(irr::video::EDT_OPENGL, resolution, depth, true, true, true, NULL); // TODO: Change last parameter
if(device==NULL)
{
std::cout << "Unable to create device! Do you have graphics drivers installed?" << std::endl;
return 1;
}
//Open data files
device->getFileSystem()->addFileArchive("Resources",true,true,irr::io::EFAT_ZIP);
device->getFileSystem()->addFileArchive("Video.tar");
device->getFileSystem()->addFileArchive("Textures.tar");
device->getFileSystem()->addFileArchive("Models.tar");
device->getFileSystem()->addFileArchive("Audio.tar");
//Load first room.
loading* loadingScreen = new loading(device);
fps *fpsLevel = new fps();
pthread_t creationThread;
struct load_struct loadingStruct;
loadingStruct.device = device;
loadingStruct.fpsLevel = fpsLevel;
//pthread_create(creationThread,NULL,load,(void *)&loadingStruct); Fix me!
while(loading==false)
{
loadingScreen->update();
std::this_thread::sleep_for(std::chrono::milliseconds(1000/60));
}
loadingScreen->kill();
// Run first room.
fpsLevel->run();
//Clean up.
device->drop();
return 0;
}
Вот мой файл load.h:
#include <irrlicht.h>
#include <string>
#ifndef LOADING_H
#define LOADING_H
class loading
{
public:
loading(irr::IrrlichtDevice *device);
void update();
void kill();
protected:
int slide;
static const int SLIDES_AMOUNT = 60;
const std::string FILENAME_TEMPLATE = "Loading_Screen/%.png";
irr::video::ITexture* slides[SLIDES_AMOUNT];
};
#endif // LOADING_H
Любая помощь будет оценена!
Проблема может быть вызвана тем, что у вас есть две разные вещи, называемые loading
:
Во-первых, там ваша class loading
. Но тогда также существует переменная bool loading
. Поэтому, когда вы это делаете:
loading* loadingScreen = new loading(device);
компилятор сталкивается с неоднозначностью и, кажется, предпочитает переменную loading
по типу loading
(я не C++ про и не может объяснить, почему это так, я думаю, это потому, что переменная является наиболее " недавнее "определение этого имени).
Исправление довольно просто: сделайте два имени разными. Поскольку C++ чувствителен к регистру, вы должны принять соглашение о начале имен классов с заглавной буквой: сделать этот class Loading
и Loading* loadingScreen = new Loading(device);
,
loading
не имеет конструктора по умолчанию, который будет вызыватьсяnew loading()
.