DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Is this legal? (http://www.daniweb.com/forums/thread132741.html)

titaniumdecoy Jul 4th, 2008 6:12 pm
Is this legal?
 
If I declare a struct node, is the following legal in C++?

node nodes_array[vector.size()];


I know this is not legal in C. However, my C++ compiler does not complain. Is this only in recent versions of C++, or has this always been legal in C++?

Ancient Dragon Jul 4th, 2008 6:47 pm
Re: Is this legal?
 
Depends on the compiler -- most c++ compilers will complain about that.

sarehu Jul 4th, 2008 9:04 pm
Re: Is this legal?
 
In C99, the latest C standard, that would be legal. (Well, not the "vector.size()", but the runtime initialization of the array size.) You can use

scoped_array<node> nodes_array(new node[vector.size()]);

instead -- if you have the boost libraries installed.


All times are GMT -4. The time now is 12:54 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC