Jump to content
  • Advertisement
Sign in to follow this  
sevak

const

This topic is 5019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Thinking in C++ says that this code is Illegal. However, when I put this code and compile it in DEVC++ i don't get an error. I don't know why it would be illegal. Is thinking in C++ wrong? //: C08:Constag.cpp // Constants and aggregates const int i[] = { 1, 2, 3, 4 }; //! float f[i[3]]; // Illegal struct S { int i, j; }; const S s[] = { { 1, 2 }, { 3, 4 } }; //! double d[s[1].j]; // Illegal int main() {} ///:~

Share this post


Link to post
Share on other sites
Advertisement
I believe its because array indices require a constant expression (0, 1, 2, 3, ...) and not a const variable. Different compilers might handle this differently, but I can't get it to compile in MSVC++ 6.

Share this post


Link to post
Share on other sites
Are you compiling the code exactly as you typed it? Because the illegal expressions are commmented out...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!