Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Unable to declare a const static int vairable ???

Unable to declare a const static int vairable ???

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HAHAHA_NEXT
    wrote on last edited by
    #1

    I have my ATL built CoClass. In its header file i have: static const int MAX_SPEED = 500; But the compiler refuses to compile and throw me this freaking error. c:\documents and settings\antonz\desktop\anton\c++ tests\atlcarserver\atlcocar.h(41) : error C2258: illegal pure syntax, must be '= 0' :confused: Can anybody enlighten an idiot. X|

    A M M 3 Replies Last reply
    0
    • H HAHAHA_NEXT

      I have my ATL built CoClass. In its header file i have: static const int MAX_SPEED = 500; But the compiler refuses to compile and throw me this freaking error. c:\documents and settings\antonz\desktop\anton\c++ tests\atlcarserver\atlcocar.h(41) : error C2258: illegal pure syntax, must be '= 0' :confused: Can anybody enlighten an idiot. X|

      A Offline
      A Offline
      antlers
      wrote on last edited by
      #2

      You can't initialize a static const in the class definition (confuses the compiler). Declare the variable in the class definition, then in the .cpp file put const int CoClass::MAX_SPEED = 500;

      1 Reply Last reply
      0
      • H HAHAHA_NEXT

        I have my ATL built CoClass. In its header file i have: static const int MAX_SPEED = 500; But the compiler refuses to compile and throw me this freaking error. c:\documents and settings\antonz\desktop\anton\c++ tests\atlcarserver\atlcocar.h(41) : error C2258: illegal pure syntax, must be '= 0' :confused: Can anybody enlighten an idiot. X|

        M Offline
        M Offline
        Maxwell Chen
        wrote on last edited by
        #3

        ISO C++ allows 'static const' variables as class members, as:

        // Either in .cpp or in .h.
        class MyClass
        {
        static const _iN = 3;
        };

        But not VC++6. ;P Maxwell Chen

        1 Reply Last reply
        0
        • H HAHAHA_NEXT

          I have my ATL built CoClass. In its header file i have: static const int MAX_SPEED = 500; But the compiler refuses to compile and throw me this freaking error. c:\documents and settings\antonz\desktop\anton\c++ tests\atlcarserver\atlcocar.h(41) : error C2258: illegal pure syntax, must be '= 0' :confused: Can anybody enlighten an idiot. X|

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          At the risk of annoying whoever posted on this subject yesterday:

          enum { MAX_SPEED = 500 };

          The ability to initialise a constant within the class declaration was added to C++ quite late in the standardisation process, and VC6 doesn't support it. Stability. What an interesting concept. -- Chris Maunder

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups