Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 1
    k, if initialization takes time and I still want it, is tehre anyhow to make my pointers come null without setting it manually? see, not because I don't want to right it, because I seem that I will never ever use unitiliazed pointers with trash on their address Commented Dec 15, 2009 at 22:24
  • 1
    You initialise class members in the class's constructor - that's how C++ works. Commented Dec 15, 2009 at 22:27
  • 3
    @Jonathan: but null is trash too. You can't do anything useful with a null pointer. Dereferencing one is just as much an error. Create pointers with proper values, not nulls. Commented Dec 15, 2009 at 22:29
  • 2
    Initialising apointer to Nnull can be a sensible thing to do.And there are several operations you can perform on null pointers - you can test them and you can call delete on them. Commented Dec 15, 2009 at 22:31
  • 4
    If you're never going to use a pointer without explicitly initializing it, it doesn't matter what it contained before you gave it a value, and under the C and C++ principle of paying for only what you use, it isn't done automatically. If there is an acceptable default value (usually the null pointer), you should initialize it. You can initialize it or leave it uninitialized, your choice. Commented Dec 15, 2009 at 22:33