Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The difference between new node() and new node?

0 views
Skip to first unread message

remlostime

unread,
Sep 5, 2008, 6:52:18 AM9/5/08
to
now, I define the struct following:
struct node
{
bool match;
node* child[27];
};

What's the difference between
1) node *Trie=new node(); and 2) node *Trie = new node;

Linlin Yan

unread,
Sep 5, 2008, 7:38:30 AM9/5/08
to

no difference.

James Kanze

unread,
Sep 5, 2008, 8:34:16 AM9/5/08
to

new Node() zero initializes the data, i.e. match will be false,
and all of the pointers will be NULL. new Node doesn't; the
contents are undefined, and reading them (before having set them
otherwise) is undefined behavior.

--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Juha Nieminen

unread,
Sep 5, 2008, 3:33:56 PM9/5/08
to
James Kanze wrote:
> new Node() zero initializes the data, i.e. match will be false,
> and all of the pointers will be NULL. new Node doesn't

Btw, is there anything equivalent for allocating arrays?

Thomas J. Gritzan

unread,
Sep 5, 2008, 4:16:24 PM9/5/08
to
Juha Nieminen schrieb:

Sure.

// allocates uninitialized ints
int* arry1 = new int[100];

// allocates ints initialized to 0 on recent (=conformant) compilers
int* arry2 = new int[100]();

// allocates ints initialized to 0 on all compilers
std::vector<int> arry3(100);

--
Thomas

0 new messages