473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

The difference between new node() and new node?

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;
Sep 5 '08 #1
4 2100
On Sep 5, 6:52*pm, remlostime <remlost...@gmail.comwrote:
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.
Sep 5 '08 #2
On Sep 5, 12:52 pm, remlostime <remlost...@gmail.comwrote:
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;
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:ja*********@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

Sep 5 '08 #3
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?
Sep 5 '08 #4
Juha Nieminen schrieb:
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?
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
Sep 5 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: J Peterman | last post by:
Im having a nightmare trying to understand these nodes and linked lists. I've posted my code for my node.h, node.cpp, linkedlist.h and linkedlist.cpp files in separates replies. Can someone...
2
by: Ralf Wahner | last post by:
Dear Masters of XSLT Could I ask you for a clue on the following question? I'd like to use XSLT to transform an XML source file to LaTeX. In the following small example the <para> Element...
5
by: Claudio Jolowicz | last post by:
Suppose you have this document: <root> <node id="1"> <node id="4"/> <node id="5"/> </node> <node id="2"/> <node id="3"/> </root>
11
by: Allan Bruce | last post by:
I am making my own linked list implementation just to get some basic knowledge of slightly more advanced C++. I have the class below, but I get an error saying "error C2629: unexpected 'Node ('"...
5
by: Jeroen Ceuppens | last post by:
I need to put a new node at the end of the tree, that end is not te lowest in de list but the deepest (the one with the most + before it) Node A Node 1 Node 2 Node 3 Node 4: Deepest Node B:...
5
by: poldoj | last post by:
Hi all, I have a treenode control and I would like to add a node in a certain level as child. For example I know that with this code I can add a level one node plus a level two node: ...
9
by: Moses | last post by:
Hi All, How to check weather a node has sibling? Is there any function like " hasChildNodes() " Thanks in Advance Moses
3
by: Kane | last post by:
When you create node 1 you allocate memory and link it Again when you create node 2 you would allocate memory for that node in a different section of the code. Is there more efficient way where I...
4
by: matth | last post by:
I've been working on something that deals with handling a user's selection within the DOM and I'm tripping up on one last, but crucial, detail. Forgive me for the length of the code, but my...
11
by: =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?= | last post by:
at the page : <http://thoraval.yvon.free.fr/Fixed_layout/import_nodes.xhtml> when importing an svg document i have to do : document.importNode(...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.