AggrorJorn Posted April 20, 2013 Share Posted April 20, 2013 I am having a hard time creating a static pointer to a new window. I have the following: //.h public: static Leadwerks::Window* window; //cpp Leadwerks::Window* window; Test::Test() { //Create a window Test::window = Leadwerks::Window::Create("test"); Is this not possible or am I am forgetting something here? Quote Link to comment Share on other sites More sharing options...
Furbolg Posted April 20, 2013 Share Posted April 20, 2013 Can you post more / attach a sample project ? Right now, im am wondering: why you declaring "window" two times (in *.h and *.cpp) ? // Edit: (your "public:" irritated me ) Sorry my mistake, Rick is right you have to initialize the static variable and not just declare it because the static variable exists (or can exists) before your class does. Quote Link to comment Share on other sites More sharing options...
Rick Posted April 20, 2013 Share Posted April 20, 2013 @Aggror as far as I know outside the class is where you have to assign it, not just declare it. //cpp Leadwerks::Window* Test::window = NULL; 2 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 20, 2013 Author Share Posted April 20, 2013 // Edit: (your "public:" irritated me ) Could you explain why it irritated you? Since it is static I figured it wouldn't really matter whether is was public or private. @Aggror as far as I know outside the class is where you have to assign it, not just declare it. //cpp Leadwerks::Window* Test::window = NULL; Ah thanks. I actually had a working sample of this in a school project. I simply forgot the class 'Test::' before the static variable in the cpp. I actually don't have to set it NULL. It works perfect like this as well: Leadwerks::Window* Test::window; Quote Link to comment Share on other sites More sharing options...
Furbolg Posted April 21, 2013 Share Posted April 21, 2013 Could you explain why it irritated you? Since it is static I figured it wouldn't really matter whether is was public or private. I didnt realized it is a class Ah thanks. I actually had a working sample of this in a school project. I simply forgot the class 'Test::' before the static variable in the cpp. I actually don't have to set it NULL. It works perfect like this as well: Leadwerks::Window* Test::window; Only in debug mode, try this in release mode and you will wonder what an uninitialized variable can do. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.