• C++ Class help
    7 replies, posted
Okay so I'm trying to figure out this issue where the c++ compiler wont see two members of a class as "being there". Errors: [CODE]class "GooBear::Window::Window" has no member "close"[/CODE] [CODE]class "GooBear::Window::Window" has no member "update"[/CODE] main.cpp: [CODE]#include <GLFW/glfw3.h> //#include <iostream> #include "scr/Graphics/window.h" int main() { GooBear::Window::Window window( "Test Name", 600, 800); while (!window.close()) { // Error Here window.update(); // Error Here } system("pause"); return 0; }[/CODE] window.h: [CODE]#pragma once #define DEBUG 1 #if DEBUG #include <iostream> #define LOG(x) std::cout << x << std::endl #else #define LOG(x) #endif #include <GLFW/glfw3.h> #define LOG(x) std::cout << x << std::endl namespace GooBear { namespace Window { class Window { private: const char *m_Title; int m_Width, m_Height; GLFWwindow *m_Window; bool m_Closed; public: Window(const char *name, int width, int height); ~Window(); bool closed() const; void Update() const; private: bool init(); }; } }[/CODE] window.cpp: [CODE]#include "window.h" namespace GooBear { namespace Window { // Constucker Window::Window(const char *title, int width, int height) { m_Title = title; m_Width = width; m_Height = height; if (!init()) glfwTerminate(); } bool Window::init() { if (!glfwInit()){ LOG("Failed to Initialize GLFW!"); return false; } m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL); if (!m_Window) { LOG("Failed to create GLFW window!"); glfwTerminate(); return false; } glfwMakeContextCurrent(m_Window); return true; } bool Window::closed() const { return glfwWindowShouldClose(m_Window); } void Window::Update() const { glfwPollEvents(); glfwSwapBuffers(m_Window); } Window::~Window() { glfwTerminate(); LOG("System Closing."); } } } [/CODE]
Well you're caling window.close() when it's window.closed() and you have update instead of Update
The function isn't close but close[B]d [/B]and not update but [B]U[/B]&#8203;pdate Change: [code]while (!window.closed()) { window.Update(); } [/code] You should use a smart IDE which will show you proper suggestions when typing things so that you get function names and member variables spelled correctly for you, this way trivial things like this won't happen.
[QUOTE=Karmah;52661042]The function isn't close but close[B]d [/B]and not update but [B]U[/B]&#8203;pdate Change: [code] while (!window.closed()) { window.Update(); } [/code][/QUOTE] Better thing to do for update is change the name to update() so it matches.
tomato tomato Either will work. He could also change the function from closed to close so that he no longer misspelled line 10. But clearly he didn't know why those errors were even thrown in the first place. Being consistent and having a proper naming convention is entirely up to him to do.
[QUOTE=Karmah;52661055]tomato tomato Either will work. Being consistent and having a proper naming convention is entirely up to him to do[/QUOTE] True, just trying to make his life a little easier so something like that doesn't happen again. It prevents stuff like "Did I name it 'doMath' or 'DoMath'?" situations.
[QUOTE=Karmah;52661042]The function isn't close but close[B]d [/B]and not update but [B]U[/B]&#8203;pdate Change: [code]while (!window.closed()) { window.Update(); } [/code] You should use a smart IDE which will show you proper suggestions when typing things so that you get function names and member variables spelled correctly for you, this way trivial things like this won't happen.[/QUOTE] Im using Visual Studio 2017, what would you recommend tho? FlakTheMighty Thanks <3
[QUOTE=pineappleplay;52661277]Im using Visual Studio 2017, what would you recommend tho? FlakTheMighty Thanks <3[/QUOTE] Visual studios has the features he's talking about - you'll just want to learn how to use them. When you start typing a function it'll highlight autocomplete options, and if it can't find the function you're talking about it'll highlight it with a red underline (like MS word spellcheck) to warn you.
Sorry, you need to Log In to post a reply to this thread.