Hey guys, so I came across some weird errors. I had a class that would keep calling its destructor right after the constructor and I'm not sure why. I ended up getting to this:
class test
{
private:
glm::vec2 screen;
GLuint VBO;
SDL_Window * win;
SDL_GLContext g;
public:
test (std::string Name);
~test ();
};
test::test(std::string Name){
}
This call does absolutely nothing yet whenever I call it, my destructor is called right after. Whats weird is if I don't have the string as a parameter (but I could have other data types), the destructor isn't called. Does anyone know why this happens specifically with strings?
The last question I have is when I make my constructor look like this, it crashes:
test::test (std::string _Name, unsigned int screenx, unsigned int screeny) :
Name (_Name),
screen (glm::vec2(screenx, screeny)),
win (SDL_CreateWindow(Name.c_str(),100,100,screen.x,screen.y,SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL)),
g (SDL_GL_CreateContext(win))
Assuming I made a new member of type std::string called Name (which I did), why isn't it initialized properly in the initializer list? The only reason it crashes is because I use Name.c_str() in the SDL_CreateWindow which leads me to believe its undefined but why should it be if I set it to the parameter? (BTW, the only difference between this and the top is Name (_Name) and the Name.c_str() in SDL_CreateWindow). Also, I'm using VS2010 if that makes a difference.