Jump to content

C++ static window pointer


AggrorJorn
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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 wink.png)

 

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.

Link to comment
Share on other sites

// Edit: (your "public:" irritated me wink.png)

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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...