Is this legal?

Thread Solved
Reply

Join Date: Mar 2007
Posts: 36
Reputation: titaniumdecoy is on a distinguished road 
Solved Threads: 4
titaniumdecoy's Avatar
titaniumdecoy titaniumdecoy is offline Offline
Light Poster

Is this legal?

 
0
  #1
Jul 4th, 2008
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++?
Last edited by titaniumdecoy; Jul 4th, 2008 at 6:12 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,160
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1437
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Is this legal?

 
0
  #2
Jul 4th, 2008
Depends on the compiler -- most c++ compilers will complain about that.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 269
Reputation: sarehu is on a distinguished road 
Solved Threads: 22
sarehu's Avatar
sarehu sarehu is offline Offline
Posting Whiz in Training

Re: Is this legal?

 
0
  #3
Jul 4th, 2008
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

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

instead -- if you have the boost libraries installed.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC