Connecting Tech Pros Worldwide Forums | Help | Site Map

The difference between new node() and new node?

remlostime
Guest
 
Posts: n/a
#1: Sep 5 '08
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
Guest
 
Posts: n/a
#2: Sep 5 '08

re: The difference between new node() and new node?


On Sep 5, 6:52*pm, remlostime <remlost...@gmail.comwrote:
Quote:
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;
no difference.
James Kanze
Guest
 
Posts: n/a
#3: Sep 5 '08

re: The difference between new node() and new node?


On Sep 5, 12:52 pm, remlostime <remlost...@gmail.comwrote:
Quote:
now, I define the struct following:
struct node
{
bool match;
node* child[27];
};
Quote:
What's the difference between
1) node *Trie=new node(); and 2) node *Trie = new node;
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.kanze@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
Guest
 
Posts: n/a
#4: Sep 5 '08

re: The difference between new node() and new node?


James Kanze wrote:
Quote:
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
Guest
 
Posts: n/a
#5: Sep 5 '08

re: The difference between new node() and new node?


Juha Nieminen schrieb:
Quote:
James Kanze wrote:
Quote:
>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?
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<intarry3(100);

--
Thomas
Closed Thread