0

I have the code: loading* loadingScreen = new loading(device);

When I compile the program, the compiler complains that loading screen wasn't declared:

error: 'loadingScreen' was not declared in this scope
     loading* loadingScreen = new loading(device);
              ^

I'm unsure what's causing this. What I've tried:

  • Rewriting it so that the constructor isn't run.
  • Relocating the declaration to a different section of code.
  • Making sure my classes are included correctly.

Here's my main.cpp file:

#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;
}

Here's my loading.h file:

#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

Any help would be appreciated!

5
  • Can you provide more context about where the problematic line of code is? With just what you've provided here, I don't think there's enough information to help out. Commented Jan 28, 2015 at 19:17
  • 1
    I think that the error you're mentioning is the second error, and it's a false positive caused by the first error. Namely that loading has no default constructor to be called by new loading(). Commented Jan 28, 2015 at 19:24
  • What happens when you go just ==> loading* loadingScreen = new loading; Commented Jan 28, 2015 at 22:15
  • I kinda figured that I'd be voted down here... But I really am stuck and I'm not seeing this issue anywhere else. This is the first error the compiler is mentioning, so it can't be a false positive. new loading() is actually supposed to be new loading(device); That was a typo on my part and will be corrected above. I will also attach my main class. Commented Jan 28, 2015 at 22:58
  • 1
    You have a bool loading and a class loading. Rename the bool at the top of main.cpp and wonder. Commented Jan 28, 2015 at 23:54

1 Answer 1

2

The problem might be caused by the fact that you've got two different things called loading:

First, there's your class loading. But then, there's also the variable bool loading. So when you do:

loading* loadingScreen = new loading(device);

the compiler is confronted with an ambiguity and seems to prefer the variable loading over the type loading (I'm not an C++ pro and can't explain why this is the case; my guess is it's because the variable is the most "recent" definition of that name).

The fix is pretty easy: make the two names different. Since C++ is case-sensitive you should adopt the convention of starting class names with an uppercase letter: make that class Loading and Loading* loadingScreen = new Loading(device);.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.