Base class undefined. How would I go about fixing this issue?

30 Views Asked by At

I want to create the object "keyEventsInstance" on the stack as a private member of the class "MultiLauncher" (see MultiLauncher.h) and then have keyEvents::processKey(uint key) method call MultiLauncher.exit() in order for the app to exit. How do I do this properly? I wanna avoid using pointers and heap memory as much as possible...

As it is now, it gives me this error: keyEvents.h error: "MultiLauncher": base class undefined.

defines.h

#pragma once

#define uint unsigned int
#define uint8 unsigned char
#define uint16 unsigned short
#define uint32 unsigned long
#define uint64 unsigned long long

#define int8 char
#define int16 short
#define int32 long
#define int64 long long

#define WINDOW_DEFAULT_WIDTH 1920
#define WINDOW_DEFAULT_HEIGHT 1080
#define WINDOW_DEFAULT_NAME "MultiLauncher"
#define INIT_FAIL -1

MultiLauncher.h

#pragma once
#include <fstream>
#include <sstream>
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include "defines.h"
#include "readFile.h"
#include "createShader.h"
#include "figure.h"
#include "keyEvents.h"

class MultiLauncher
{
public:
    MultiLauncher();
    ~MultiLauncher();

private:
    uint windowWidth;
    uint windowHeight;
    const char* windowName;
    bool keepRunningGame = 1;

    keyEvents keyEventsInstance;

private:
    static void callback(GLFWwindow* window, unsigned int codepoint);

public:
    int run();
    GLFWwindow* initApp();
    void exit();
    

};

MultiLauncher.cpp

#include "MultiLauncher.h"

MultiLauncher::MultiLauncher() :
    windowWidth(WINDOW_DEFAULT_WIDTH), windowHeight(WINDOW_DEFAULT_HEIGHT), windowName(WINDOW_DEFAULT_NAME)
{

}
MultiLauncher::~MultiLauncher()
{

}

int MultiLauncher::run()
{
    std::cout << "Begin..." << std::endl;
    GLFWwindow* window = initApp();
    //character input
    glfwSetCharCallback(window, callback);

    figure triangle;

    /* Game Loop until the user closes the window */
    while (!glfwWindowShouldClose(window) && keepRunningGame)
    {

        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        triangle.buildFigure();
        triangle.drawFigure();

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }
    glfwTerminate();
    return 0;
}

GLFWwindow* MultiLauncher::initApp()
{
    /* Initialize the library */
    if (glfwInit() != 1)
    {
        std::cout << "GLFW failed to initialize\n";
        std::cin.get();
    }

    /* Create a windowed mode window and its OpenGL context */
    GLFWwindow* window = glfwCreateWindow(WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT, WINDOW_DEFAULT_NAME, glfwGetPrimaryMonitor(), NULL);
    if (!window)
        glfwTerminate();

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    

    if (glewInit() != GLEW_OK)
    {
        std::cout << "GLEW failed to initialize\n";
        std::cin.get();
    }
    return window;
}

void MultiLauncher::exit()
{
    //save game progress
    keepRunningGame = 0; //exit game loop
}


void MultiLauncher::callback(GLFWwindow* window, unsigned int codepoint)
{
    std::cout << codepoint << std::endl;
    keyEvents::processKey(codepoint);
}

keyEvents.h

#pragma once
#include "defines.h"
#include "MultiLauncher.h"

class keyEvents:public MultiLauncher
{
public:
    keyEvents();
    ~keyEvents();
public:
    static void processKey(uint key);
};

keyEvents.cpp

#include "keyEvents.h"


void keyEvents::processKey(uint key)
{
    if (key == 97)  //escape key
        MultiLauncher.exit();
}


keyEvents::keyEvents()
{}
keyEvents::~keyEvents()
{}

Tried #including MultiLauncher.h in keyEvents.h Still doesn't work. I think its got something to do with cycling referencing? but not sure.

0

There are 0 best solutions below