Initialising array of pointers

Started by
2 comments, last by edotorpedo 21 years, 2 months ago
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
Edo
Advertisement
Like this:

class QuadTree {

public:
QuadTree();
~QuadTree();

private:
(QuadTree*) children[4];

}

QuadTree::QuadTree() {

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

}
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]
f@dzhttp://festini.device-zero.de
ZeroMemory( Children, sizeof( QuadTree ) << 2 );


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

This topic is closed to new replies.

Advertisement