What is the difference between `new` and `new()` for a struct in C/C++? -


possible duplicate:
do parentheses after type name make difference new?

in code, saw struct this:

typedef struct mystruct {     int numberone;     int numbertwo; } mystruct; 

later, tried instantiating 1 of these structs using

mystruct *pstruct = new mystruct(); 

which worked fine visual studio 2010, failed obscure linker error on different compiler. took while until found out omitting braces this

mystruct *pstruct = new mystruct; 

solved issue.

so, difference between these 2 invocations , 1 right 1 use?

new mystruct performs default initialization, in case nothing.

new mystruct() performs value initialization, in case sets both int variables zero.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -