Error on &m_Width and &m_Height
Feb 21, 2017 at 8:29am UTC
So im messing around with GLFW and I am trying to create a window with a viewport to make sure that stuff is centered around the screen, i seem to come with this issue but i'm not entirely sure what is wrong as I believe I have covered what should be covered.
Error:
1 2
Severity Code Description Project File Line Suppression State
Error C3867 'benji::graphics::Window::getWidth' : non-standard syntax; use '&' to create a pointer to member Benji-core c:\users\ryanm\documents\visual studio 2015\projects\benji-core\benji-core\main.cpp 11
1 2
Severity Code Description Project File Line Suppression State
Error C3867 'benji::graphics::Window::getHeight' : non-standard syntax; use '&' to create a pointer to member Benji-core c:\users\ryanm\documents\visual studio 2015\projects\benji-core\benji-core\main.cpp 11
Window.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#include "window.h"
namespace benji { namespace graphics {
Window::Window(const char *title, int width, int height) {
m_Title = title;
m_Width = width;
m_Height = height;
if (!init()) {
glfwTerminate();
}
}
Window::~Window() {
glfwTerminate();
}
bool Window::init() {
if (!glfwInit()) {
std::cout << "Failed to initialize GLFW!" << std::endl;
return false ;
}
m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL);
if (!m_Window) {
std::cout << "Failed to create GLFW window!" << std::endl;
return false ;
}
glfwMakeContextCurrent(m_Window);
return true ;
}
void Window::clear() const {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void Window::update(){
glfwPollEvents();
glfwGetFramebufferSize(m_Window, &m_Width, &m_Height);
glfwSwapBuffers(m_Window);
}
bool Window::closed() const {
return glfwWindowShouldClose(m_Window) == 1;
}
}}
window.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#pragma once
#include <GLFW\glfw3.h>
#include <iostream>
namespace benji {
namespace graphics {
class Window {
private :
const char *m_Title;
int m_Width, m_Height;
GLFWwindow *m_Window;
bool m_Closed;
public :
Window(const char *title, int width, int height);
~Window();
bool closed() const ;
void update();
void clear() const ;
int getWidth() const {
return m_Width;
}
int getHeight() const { return m_Height; }
private :
bool init();
};
}
}
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "src\graphics\window.h"
int main() {
using namespace benji;
using namespace graphics;
Window window("Benji Engine" , 1280, 720);
glClearColor(0.2f, 0.3f, 0.8f, 1.0f);
std::cout << glGetString(GL_VERSION) << std::endl;
while (!window.closed()) {
std::cout << window.getWidth << ", " << window.getHeight << std::endl;
window.clear();
glBegin(GL_TRIANGLES);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.0f, 0.5f);
glVertex2f(0.5f, -0.5f);
glEnd();
window.update();
}
return 0;
}
main.h
1 2 3 4 5 6 7 8
#pragma once
class main
{
public :
main();
~main();
};
Again not totally sure that I can see the issue but then again I haven't slept for 20 hours so this might be the case.
any help my dudes?
Feb 21, 2017 at 8:54am UTC
You have forgot the parentheses after the function names.
Feb 21, 2017 at 2:46pm UTC
Oh so I did, thank you man!
Topic archived. No new replies allowed.