Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6672383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:30:06+00:00 2026-05-26T03:30:06+00:00

I don’t want to use pointers when I don’t have to, but here’s the

  • 0

I don’t want to use pointers when I don’t have to, but here’s the problem: in the code below if I remove the asterisk and make level simply an object, and of course remove the line level = new Level; I get a runtime error, the reason being that level is then initialized on the first line, BEFORE initD3D and init_pipeline – the methods that set up the projection and view for use. You see the problem is that level uses these two things but when done first I get a null pointer exception.

Is this simply a circumstance where the answer is to use a pointer? I’ve had this problem before, basically it seems extremely vexing that when a class type accepts no arguments, you are essentially initializing it where you declare it…. or am I wrong about this last part?

Level* level;

D3DMATRIX* matProjection,* matView;

//called once
void Initialise(HWND hWnd)
{
initD3D(hWnd);
    init_pipeline();

level = new Level;
}

I’m coming from c# and in c#, you are simply declaring a name with the line Level level; arguments or not, you still have to initialize it at some point.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:30:07+00:00Added an answer on May 26, 2026 at 3:30 am

    You are correct that if you do:

    Level level;
    

    then level will be instantiated at that point. That is because the above expression, which appears to be a global, isn’t just a declaration, but also a definition.

    If this is causing you problems because Level is being instantiated before something else is being instantiated, then you have encountered a classic reason why globals suck.

    You have attempted to resolve this by making level a pointer and then “initializing” it later. Wjhat might suprise you is that level is still being instantiated at the same point. The difference now is the type of level. It’s not a Level anymore; now its a pointer-to-level. If you examine the value of level when your code enters Initialize you’ll see that it has a value of NULL.

    It has a value of NULL instead of a garbage value because globals are static initialized, which in the case here, means zero-initialized.

    But this is all somewhat tangential to the real problem, which is that you are using globals in the first place. If you need to instantiate objects in a specific order, then instantiate them in that order. Don’t use globals, and you may find that by doing that, you don’t need to use pointers, either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

don't know better title for this, but here's my code. I have class user
I don't like Jackson. I want to use ajax but with Google Gson. So
Don't ask me how but I'm in a situation where I have DCPs published
Don't be scared of the extensive code. The problem is general. I just provided
I don't know why, but this code worked for me a month ago... maybe
Don't know if I worded the question right, but basically what I want to
Don't be afraid to use any technical jargon or low-level explanations for things, please.
Don't they both have to convert to machine code at some point to execute
Don't ask why but I have the requirement to draw a border around certain
Don't know if this is an eclipse specific problem but whenever I declare a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.