I'm working on university coursework and attempting to build a window using GLFW. I've been following the documentation and video series we were given to follow (The Hazel Engine by The Cherno on Youtube), but have run into an issue with abstract classes.
I really struggle to understand both pointers and abstraction, so am really struggling to understand what I'm doing, but I believe it's attempting to call the inherited 'create' function from Window, to build a WinWindow (named as such because it's Windows OS specific), but I'm getting an error C2259 "'Engine::WinWindow' cannot instantiate abstract class" at line 9 of winWindow.cpp
The relevant code follows:
window.h
#pragma once
#include "graphicsContext.h"
#include <string>
#include <functional>
namespace Engine {
class Event; // Be replaced
struct WindowProperties
{
std::string m_title;
unsigned int m_width;
unsigned int m_height;
bool m_isFullScreen;
bool m_isVSync;
WindowProperties(const std::string& title = "My Window", unsigned int width = 800, unsigned int height = 600, bool fullscreen = false) : m_title(title), m_width(width), m_height(height), m_isFullScreen(fullscreen) {}
};
class Window
{
public:
using EventCallbackFn = std::function<void(Event&)>;
virtual void init(const WindowProperties& properties) = 0;
virtual void close() = 0;
virtual ~Window() {};
virtual void onUpdate(float timestep) = 0;
virtual void onResize(unsigned int width, unsigned int height) = 0;
virtual void setVSync(bool VSync) = 0;
virtual void setEventCallback(const EventCallbackFn callback) = 0;
virtual unsigned int getWidth() const = 0;
virtual unsigned int getHeight() const = 0;
virtual void* getNativeWindow() const = 0;
virtual bool isFullScreenMode() const = 0;
virtual bool isVSync() const = 0;
static Window* create(const WindowProperties& properties = WindowProperties());
protected:
std::shared_ptr<GraphicsContext> m_context;
};
}
winWindow.h
#pragma once
#include "windows/window.h"
#include <GLFW/glfw3.h>
namespace Engine {
class WinWindow : public Window {
public:
WinWindow(const WindowProperties& properties);
virtual ~WinWindow();
void onUpdate();// override;
inline unsigned int getWidth() const override { return m_data.width; }
inline unsigned int getHeight() const override { return m_data.height; }
inline void SetEventCallback(const EventCallbackFn& callback) override { m_data.eventCallback = callback; }
void setVSync(bool enabled) override;
bool isVSync() const override;
private:
virtual void init(const WindowProperties& properties);
virtual void shutdown();
GLFWwindow* m_window;
struct windowData {
std::string title;
unsigned int width, height;
bool vSync;
EventCallbackFn eventCallback;
};
windowData m_data;
};
}
winWindow.cpp
#include "engine_pch.h"
#include "Platform/win/winWindow.h"
namespace Engine {
static bool GLFWinit = false;
Window* Window::create(const WindowProperties& properties) {
return new WinWindow(properties);
}
WinWindow::WinWindow(const WindowProperties& properties) {
init(properties);
}
WinWindow::~WinWindow() {
shutdown();
}
void WinWindow::init(const WindowProperties& properties) {
m_data.title = properties.m_title;
m_data.width = properties.m_width;
m_data.height = properties.m_height;
LOG_INFO("Window: {0} - ({1}, {2})", properties.m_title, properties.m_width, properties.m_height);
if (!GLFWinit) {
GLFWinit = true;
}
m_window = glfwCreateWindow((int)properties.m_width, (int)properties.m_height, m_data.title.c_str(), nullptr, nullptr);
glfwMakeContextCurrent(m_window);
glfwSetWindowUserPointer(m_window, &m_data);
setVSync(true);
}
void WinWindow::shutdown() {
glfwDestroyWindow(m_window);
}
void WinWindow::onUpdate() {
glfwPollEvents();
glfwSwapBuffers(m_window);
}
void WinWindow::setVSync(bool enabled) {
if (enabled)
glfwSwapInterval(1);
else
glfwSwapInterval(0);
m_data.vSync = enabled;
}
bool WinWindow::isVSync() const {
return m_data.vSync;
}
}
I'm also getting a separate error C3668, which says "'Engine::WinWindow::SetEventCallback': method with override specifier 'override' did not override any base class methods". Although I could be wildly wrong, I believe this is just because it is as of right now, unused.
Any help with these issues will be greatly appreciated, but could you attempt to explain yourself as much as possible to help me understand what's happening and the decision making of what's going on, as I'm really struggling to follow all of this?