• Advertisement

Archived

This topic is now archived and is closed to further replies.

Initialising array of pointers

This topic is 5500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an array of 4 pointers in a class called QuadTree. In my constructor, how do I initialize each of these pointers to NULL class QuadTree { public: QuadTree(); ~QuadTree(); private: QuadTree *children[4]; } Like this: QuadTree::QuadTree():children(NULL) {} or like this: QuadTree::QuadTree() { for (int i = 0; i < 4; i++) children = NULL; } Thanks, Edo

Share this post


Link to post
Share on other sites
Advertisement
Like this:

class QuadTree {

public:
QuadTree();
~QuadTree();

private:
(QuadTree*) children[4];

}

QuadTree::QuadTree() {

for (int i = 0; i < 4; i++) children = NULL;

}

Share this post


Link to post
Share on other sites
quote:
Original post by edotorpedo
QuadTree::QuadTree():children(NULL) {}



bad idea, will only set the pointer to the pointers to null

for-loop. does the right thing and a good compiler will probably optimize it.

memset(children, 0, 4*sizeof(QuadTree*));
probably too "low level" for some peoples taste *g*

[edited by - Trienco on January 30, 2003 12:21:24 PM]

Share this post


Link to post
Share on other sites
ZeroMemory( Children, sizeof( QuadTree ) << 2 );



/* Bullmax */
-------------
Reality has many forms : good and evil, black and white, yin and yang.

Share this post


Link to post
Share on other sites

  • Advertisement