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++?

Recommended Answers

All 2 Replies

Depends on the compiler -- most c++ compilers will complain about that.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.