class A{static const int b = 1; };

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    class A{static const int b = 1; };

    I read in "Thinking in C++" this code works:
    ---------
    class A
    {
    static const int b = 1;
    };
    ---------
    but it doesn't!
    I do something wrong?
    I use VC++6 and it returns:
    -------
    error C2258: illegal pure syntax, must be '= 0'
    error C2252: 'b' : pure specifier can only be specified for functions
    -------


  • WW

    #2
    Re: class A{static const int b = 1; };

    <- Chameleon -> wrote:[color=blue]
    > I read in "Thinking in C++" this code works:
    > ---------
    > class A
    > {
    > static const int b = 1;
    > };
    > ---------
    > but it doesn't!
    > I do something wrong?[/color]

    No. VC6 is non-standard in this matter. The usual fix is the enum-as-const
    "idiom". Just do it like this:

    class A
    {
    enum { b = 1; };
    };

    --
    WW aka Attila


    Comment

    • Victor Bazarov

      #3
      Re: class A{static const int b = 1; };

      "WW" <wolof@freemail .hu> wrote...[color=blue]
      > <- Chameleon -> wrote:[color=green]
      > > I read in "Thinking in C++" this code works:
      > > ---------
      > > class A
      > > {
      > > static const int b = 1;
      > > };
      > > ---------
      > > but it doesn't!
      > > I do something wrong?[/color]
      >
      > No. VC6 is non-standard in this matter. The usual fix is the[/color]
      enum-as-const[color=blue]
      > "idiom". Just do it like this:
      >
      > class A
      > {
      > enum { b = 1; };[/color]

      enum { b = 1 };
      [color=blue]
      > };[/color]

      Victor


      Comment

      • Alexander Terekhov

        #4
        Re: class A{static const int b = 1; };


        Victor Bazarov wrote:
        [...][color=blue][color=green]
        > > enum { b = 1; };[/color]
        >
        > enum { b = 1 };[/color]

        "The actual eyeballs, lying within an ea^H^H^H^H^HBaz arov's skull, are
        huge by our standards, taking up more room than the brain itself!"



        regards,
        alexander.

        Comment

        • WW

          #5
          Re: class A{static const int b = 1; };

          Victor Bazarov wrote:[color=blue][color=green]
          >> class A
          >> {
          >> enum { b = 1; };[/color]
          >
          > enum { b = 1 };
          >[color=green]
          >> };[/color][/color]

          Thanks for the correction. I forgot to remove the ;. It is so little I did
          not see it is there. That is again a proof that size does not matter ;-)

          --
          WW aka Attila


          Comment

          • WW

            #6
            Re: class A{static const int b = 1; };

            Alexander Terekhov wrote:[color=blue]
            > Victor Bazarov wrote:
            > [...][color=green][color=darkred]
            >>> enum { b = 1; };[/color]
            >>
            >> enum { b = 1 };[/color]
            >
            > "The actual eyeballs, lying within an ea^H^H^H^H^HBaz arov's skull, are
            > huge by our standards, taking up more room than the brain itself!"[/color]

            I assume Alexander meant you have eagle eyes. And nothing about Victor's
            brain.

            Alexander, you will really need a bodyguard. My father has jokes like this
            and the people of his village did confess to me that they have sometimes
            played with the idea to check if his brain differs from a normal one. ;-)

            --
            WW aka Attila


            Comment

            • Victor Bazarov

              #7
              Re: class A{static const int b = 1; };

              "WW" <wolof@freemail .hu> wrote...[color=blue]
              > [...]
              > I assume Alexander meant [...][/color]

              He didn't mean anything. He can't mean anything.
              He has no device with which to mean.


              Comment

              • WW

                #8
                Re: class A{static const int b = 1; };

                Victor Bazarov wrote:[color=blue]
                > "WW" <wolof@freemail .hu> wrote...[color=green]
                >> [...]
                >> I assume Alexander meant [...][/color]
                >
                > He didn't mean anything. He can't mean anything.
                > He has no device with which to mean.[/color]

                I see. He has no device with which to mean. So he cannot be mean. ;-)


                Comment

                • Alexander Terekhov

                  #9
                  Re: class A{static const int b = 1; };


                  WW wrote:
                  [...][color=blue]
                  > I assume Alexander meant you have eagle eyes. And nothing about Victor's
                  > brain.[/color]

                  Let me put it this way. Judging from Bazarov's "subdue" c.l.c++-policing
                  activity of lately, his medical treatment looks really promising. To me,
                  it seems like he'll reach the level of NeilB really soon. Amen. Default,
                  be ready (never mind your days are coming too).



                  regards,
                  alexander.

                  Comment

                  • Gianni Mariani

                    #10
                    Re: class A{static const int b = 1; };

                    Alexander Terekhov wrote:[color=blue]
                    > WW wrote:
                    > [...]
                    >[color=green]
                    >>I assume Alexander meant you have eagle eyes. And nothing about Victor's
                    >>brain.[/color]
                    >
                    >
                    > Let me put it this way. Judging from Bazarov's "subdue" c.l.c++-policing
                    > activity of lately, his medical treatment looks really promising. To me,
                    > it seems like he'll reach the level of NeilB really soon. Amen. Default,
                    > be ready (never mind your days are coming too).
                    >
                    > http://groups.google.com/groups?selm...A3F4C%40web.de[/color]

                    So what did end up happening to the butter man. Is he Alexander now ?

                    Comment

                    • Shane Beasley

                      #11
                      Re: class A{static const int b = 1; };

                      "<- Chameleon ->" <cham_gss@hotma il.NOSPAM.com> wrote in message news:<bkhadp$8e $1@nic.grnet.gr >...[color=blue]
                      > I read in "Thinking in C++" this code works:
                      > ---------
                      > class A
                      > {
                      > static const int b = 1;
                      > };
                      > ---------
                      > but it doesn't![/color]

                      <http://www.comeaucompu ting.com/tryitout/> compiles it just fine. If
                      you're going to use a compiler as a measure of code correctness, use
                      that one. :)
                      [color=blue]
                      > I do something wrong?
                      > I use VC++6 and it returns:
                      > -------
                      > error C2258: illegal pure syntax, must be '= 0'
                      > error C2252: 'b' : pure specifier can only be specified for functions
                      > -------[/color]

                      VC++6 is wrong. VC++.NET compiles it.

                      In the short term, maybe try this instead:

                      class A { enum { b = 1 }; };

                      Or, if you don't need it as a compile-time constant (e.g., for use as
                      a template parameter, size of an array, etc.), initialize it when you
                      define it in a .cpp file:

                      // A.h
                      class A {
                      static const int b;
                      };

                      // A.cpp
                      const int A::b = 1;

                      - Shane

                      Comment

                      • Victor Bazarov

                        #12
                        [OT] Re: class A{static const int b = 1; };

                        "WW" <wolof@freemail .hu> wrote...[color=blue]
                        > Victor Bazarov wrote:[color=green]
                        > > "WW" <wolof@freemail .hu> wrote...[color=darkred]
                        > >> [...]
                        > >> I assume Alexander meant [...][/color]
                        > >
                        > > He didn't mean anything. He can't mean anything.
                        > > He has no device with which to mean.[/color]
                        >
                        > I see. He has no device with which to mean. So he cannot be mean. ;-)[/color]

                        Nah. It's actually simpler. He cannot be. Unless you let him,
                        by replying to his nonsense. Two more times and you (and others
                        feeding that idiot troll) will probably join him in my killfile.
                        You don't have to care about that. I'm just pondering.


                        Comment

                        • WW

                          #13
                          Re: [OT] Re: class A{static const int b = 1; };

                          Victor Bazarov wrote:[color=blue]
                          >
                          > Nah. It's actually simpler. He cannot be. Unless you let him,
                          > by replying to his nonsense. Two more times and you (and others
                          > feeding that idiot troll) will probably join him in my killfile.
                          > You don't have to care about that. I'm just pondering.[/color]

                          If you killfile me I cannot send you my C++ language proposal for review.
                          It would be shame. How do you expect *me* to get it right? Drop me a mail
                          if you think you would have time and want to look at something like that.

                          BTW I was not trying to feed any troll, I was trying to keep the tension
                          down. Well, remind me time to time to not seek for a carrier in marriage
                          concunciling. :-(

                          --
                          WW aka Attila


                          Comment

                          • WW

                            #14
                            Re: [OT] Re: class A{static const int b = 1; };

                            WW wrote:
                            [SNIP][color=blue]
                            > tension down. Well, remind me time to time to not seek for a carrier
                            > in marriage concunciling. :-([/color]

                            And to not to teach spelling..

                            --
                            WW aka Attila


                            Comment

                            • Alexander Terekhov

                              #15
                              Re: [OT] Re: class A{static const int b = 1; };


                              Victor Bazarov wrote:[color=blue]
                              >
                              > "WW" <wolof@freemail .hu> wrote...[color=green]
                              > > Victor Bazarov wrote:[color=darkred]
                              > > > "WW" <wolof@freemail .hu> wrote...
                              > > >> [...]
                              > > >> I assume Alexander meant [...]
                              > > >
                              > > > He didn't mean anything. He can't mean anything.
                              > > > He has no device with which to mean.[/color]
                              > >
                              > > I see. He has no device with which to mean. So he cannot be mean. ;-)[/color]
                              >
                              > Nah. It's actually simpler. He cannot be. Unless you let him,
                              > by replying to his nonsense. Two more times and you (and others
                              > feeding that idiot troll) will probably join him in my killfile.[/color]

                              Aha. How scary.
                              [color=blue]
                              > You don't have to care about that. I'm just pondering.[/color]

                              Medication, Bazarov. Take a dose of anti-hysteria pills.

                              regards,
                              alexander.

                              Comment

                              Working...