visual studio 2010 - Unexplained errors in C++ -



visual studio 2010 - Unexplained errors in C++ -

i'm making little framework around opengl creating simple 2d game. when finished texture class , used in engine thogl (orthogonal opengl) class got lot of unexplained errors don't create sense. tried find can't figure out, hoped guys hem me. i'm using libraries: glew, glfw, opengl32, glm.

my code

texture.h

#pragma 1 time #include <magick++.h> #include "thogl.h" class texture { public: texture(glenum texturetarget); ~texture(); bool loadimage(const char* filename); void bind(glenum textureunit); magick::image* image; private: magick::blob blob; gluint textureobject; glenum texturetarget; };

texture.cpp

#include "texture.h" texture::texture(glenum target) { texturetarget = target; image = null; } texture::~texture() { } bool texture::loadimage(const char* filename) { seek { image = new magick::image(filename); image->write(&blob, "rgba"); } catch(magick::error error) { error (error.what()); homecoming false; } glgentextures(1, &textureobject); glbindtexture(texturetarget, textureobject); glteximage2d(texturetarget, 0, gl_rgba, image->columns(), image->rows(), 0, gl_rgba, gl_unsigned_byte, blob.data()); gltexparameterf(textureobject, gl_texture_min_filter, gl_linear); gltexparameterf(textureobject, gl_texture_mag_filter, gl_linear); homecoming true; } void texture::bind(glenum textureunit) { glactivetexture(textureunit); glbindtexture(texturetarget, textureobject); }

thogl.h

#pragma 1 time #include <gl/glew.h> #include <glfw/glfw3.h> #include <iostream> #include <fstream> #include <string> #include <glm.hpp> #include <gtx/transform.hpp> #include <map> #include "texture.h" using namespace std; class thogl { public: thogl(); ~thogl(); bool init(int windowwidth, int windowheight, const char* windowtitle); texture* createtexture(const char* texturename, const char* filename); texture* createtexture(const char* texturename); void start(void (*runcallback)()); private: void run(); glfwwindow* window; static void keycallback(glfwwindow*, int key, int scancode, int action, int mods); void setcallbacks(); void terminate(); map<string, texture*> textures; void (*runcallback)(); }; void error(const char* error);

thogl.cpp

#include "thogl.h" ofstream errorlog; thogl::thogl() { magick::image* image; magick::blob blob; seek { image = new magick::image("//lol.png"); image->write(&blob); } catch(magick::error error) { error(error.what()); } } thogl::~thogl() { } void thogl::run() { while (!glfwwindowshouldclose(window)) { runcallback(); glfwswapbuffers(window); glfwpollevents(); } } bool thogl::init(int screenwidth, int screenheight, const char* windowtitle) { errorlog.open("error.log"); if (!glfwinit()) { error("could not initialize glfw library"); homecoming false; } window = glfwcreatewindow(screenwidth, screenheight, windowtitle, null, null); if (!window) { errorlog << "error: not initialize glfw window\n"; glfwterminate(); homecoming false; } glfwmakecontextcurrent(window); glenum error = glewinit(); if (error != glew_ok) { errorlog << "error glew: " << glewgeterrorstring(error) << "\n"; homecoming false; } setcallbacks(); glclearcolor(138.f,43.f,226.f, 0); homecoming true; } void thogl::keycallback(glfwwindow* window, int key, int scancode, int action, int mods) { } void thogl::setcallbacks() { glfwsetkeycallback(window, keycallback); } void thogl::terminate() { glfwdestroywindow(window); glfwterminate(); errorlog.close(); } void error(const char* error) { errorlog << "error: " << error << "\n"; } void thogl::start(void (*callback)()) { runcallback = callback; run(); } texture* thogl::createtexture(const char* texturename, const char* filename) { texture* newtexture = new texture(gl_texture_2d); if (!newtexture->loadimage(filename)) { error("couldn't load image file"); homecoming 0; } textures.insert(make_pair(texturename, newtexture)); homecoming newtexture; } texture* thogl::createtexture(const char* texturename) { texture *newtexture = new texture(gl_texture_2d); textures.insert(make_pair(texturename, newtexture)); homecoming newtexture; }

here output when compiling on vs2010 express:

>------ build started: project: 2dengine, configuration: debug win32 ------ > thogl.cpp > texture.cpp > thogl.h(25): error c2143: syntax error : missing ';' before '*' > thogl.h(25): error c4430: missing type specifier - int assumed. note: c++ not back upwards default-int > thogl.h(25): error c4430: missing type specifier - int assumed. note: c++ not back upwards default-int > thogl.h(25): warning c4183: 'createtexture': missing homecoming type; assumed fellow member function returning 'int' > thogl.h(26): error c2143: syntax error : missing ';' before '*' > thogl.h(26): error c4430: missing type specifier - int assumed. note: c++ not back upwards default-int > thogl.h(26): error c4430: missing type specifier - int assumed. note: c++ not back upwards default-int > thogl.h(26): warning c4183: 'createtexture': missing homecoming type; assumed fellow member function returning 'int' > thogl.h(36): error c2065: 'texture' : undeclared identifier > thogl.h(36): error c2059: syntax error : '>' > thogl.h(38): error c2143: syntax error : missing ';' before '}' > texture.h(8): error c2143: syntax error : missing ';' before '{' > texture.h(24): error c2143: syntax error : missing ';' before '}' > texture.cpp(4): error c2653: 'texture' : not class or namespace name > texture.cpp(5): error c2143: syntax error : missing ';' before '{' > texture.cpp(8): error c2143: syntax error : missing ';' before '}' > texture.cpp(9): error c2653: 'texture' : not class or namespace name > texture.cpp(9): fatal error c1903: unable recover previous error(s); stopping compilation > generating code... > skipping... (no relevant changes detected) > main.cpp ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

you have circular dependency between 2 header files. include each other. compiler skips circular includes (you told #pragma once) , in file gets parsed first types other file unknown, leading errors.

to prepare this, should remove circular include (texture.h doesn't seem require thogl.h) or utilize forwards declarations of required types.

c++ visual-studio-2010 opengl

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -