why doesn't this code compile in MSVC 6.0 ? 
Author Message
 why doesn't this code compile in MSVC 6.0 ?

Hi,

the following code snippet:

 //------------------

 class dummyClass {
   static const int dummyVar = 100;

public :
    dummyClass() {} ;
    ~dummyClass() {} ;
 }

 //------------------

 does not compile in MSVC++ 6.0. I get the following errors:

error C2258: illegal pure syntax, must be '= 0'
error C2252: 'dummyVar' : pure specifier can only be specified for
functions

Can anyone explain to me why this doesn't compile?
(For a reason why it *should* compile, see
http://www.*-*-*.com/ )

Thanks,
Sageev



Sat, 03 Aug 2002 03:00:00 GMT  
 why doesn't this code compile in MSVC 6.0 ?

Quote:

>   static const int dummyVar = 100;

This line is invalid. Static variable initializers must be
outside class scope.

Change it to:

    static const int dummyVar;

and initialize it using

    dummyClass::dummyVar=100;

outside of the class definition itself

Quote:
>error C2258: illegal pure syntax, must be '= 0'
>error C2252: 'dummyVar' : pure specifier can only be specified for
>functions

The error message is because the illegal syntax
tripped up the compiler, and it misidentified the
error.


Sat, 03 Aug 2002 03:00:00 GMT  
 why doesn't this code compile in MSVC 6.0 ?
Greets,

    The reasons why it *should* compile are obviously apparent to anyone who
has read the standard.  The important thing to note is that this is a known
issue of a language feature that is not yet supported.  For a list of all
issues known so far, you should check out:

http://support.microsoft.com/support/kb/articles/q243/4/51.asp

    In the meantime, you can use an enum {} to hold those constant values.

Regards,

Joe


Quote:

> Hi,

> the following code snippet:

>  file://------------------

>  class dummyClass {
>    static const int dummyVar = 100;

> public :
>     dummyClass() {} ;
>     ~dummyClass() {} ;
>  }

>  file://------------------

>  does not compile in MSVC++ 6.0. I get the following errors:

> error C2258: illegal pure syntax, must be '= 0'
> error C2252: 'dummyVar' : pure specifier can only be specified for
> functions

> Can anyone explain to me why this doesn't compile?
> (For a reason why it *should* compile, see
> http://codeguru.developer.com/cpp/tic/tic0113.shtml )

> Thanks,
> Sageev



Sat, 03 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Doesn't compile local classes, why?

2. Why doesn't THIS compile???

3. Why doesn't this compile?

4. Why doesn't VC++ compile this?

5. Why doesn't this compile?

6. Why doesn't VC++ compile this?

7. Code doesn't work in VC 6.0

8. Old code doesn't compile with VS.NET

9. Why this code doesn't work?

10. why doesn't this code run faster?

11. Why doesn't this C code work?

12. Why doesn't this code work correctly?

 

 
Powered by phpBB® Forum Software