Thread: nulling pointers before new

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367

    nulling pointers before new

    Hello, quick question. When you are creating classes, is it always important to null any pointers within the class in the constructor. The reason, why i am asking is, a problem has just come up within my class, but as soon as i null the pointer within the constructor and deconstructor when it is being deleted, the class works fine.
    Be a leader and not a follower.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    It is good practice to set newly declared pointer to a NULL value, but it is not necessary. A pointer that is uninitialised is not a problem until something somewhere tries to dereference it.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Yeah, thats what i thought. Which is making me think there is something wrong with my class. Ta...
    Be a leader and not a follower.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM