BEFORE I EXPLODE

Discussion in 'C++' started by JKop, Sep 18, 2004.

  1. JKop

    JKop Guest

    G++ gives the most un-informative, cryptic, BULLSHIT errors
    statements.

    I'm writing a program at the moment and I have to finish it
    real soon. The problem I'm having is illustrated in the
    following:

    class Blah
    {
    private:

    int k;

    public:

    operator int()
    {
    return k;
    }

    };


    int main()
    {
    Blah const poo;

    switch (poo)
    {
    case 1:
    ;
    }

    }


    The yokie that goes in a switch statement has to be an
    integral type. My class has an "operator int()". Grand.

    Note that the "poo" object is const. If I make the poo
    object non-const, then the above code compiles. BUT WHAT
    THE HELL DIFFERENCE DOES IT MAKE IF IT'S CONST!

    Some enlightenment please,

    -JKop
    JKop, Sep 18, 2004
    #1
    1. Advertising

  2. JKop wrote:
    > G++ gives the most un-informative, cryptic, BULLSHIT errors
    > statements.
    >
    > I'm writing a program at the moment and I have to finish it
    > real soon. The problem I'm having is illustrated in the
    > following:
    >
    > class Blah
    > {
    > private:
    >
    > int k;
    >
    > public:
    >
    > operator int()
    > {
    > return k;
    > }
    >
    > };
    >
    >
    > int main()
    > {
    > Blah const poo;
    >
    > switch (poo)
    > {
    > case 1:
    > ;
    > }
    >
    > }
    >
    >
    > The yokie that goes in a switch statement has to be an
    > integral type. My class has an "operator int()". Grand.
    >
    > Note that the "poo" object is const. If I make the poo
    > object non-const, then the above code compiles. BUT WHAT
    > THE HELL DIFFERENCE DOES IT MAKE IF IT'S CONST!
    >
    > Some enlightenment please,



    operator const int()



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Sep 18, 2004
    #2
    1. Advertising

  3. JKop

    JKop Guest

    Ioannis Vranos posted:

    > JKop wrote:
    >> G++ gives the most un-informative, cryptic, BULLSHIT

    errors
    >> statements.
    >>
    >> I'm writing a program at the moment and I have to finish

    it
    >> real soon. The problem I'm having is illustrated in the

    following:
    >>
    >> class Blah
    >> {
    >> private:
    >>
    >> int k;
    >>
    >> public:
    >>
    >> operator int()
    >> {
    >> return k;
    >> }
    >>
    >> };
    >>
    >>
    >> int main()
    >> {
    >> Blah const poo;
    >>
    >> switch (poo)
    >> {
    >> case 1:
    >> ;
    >> }
    >>
    >> }
    >>
    >>
    >> The yokie that goes in a switch statement has to be an
    >> integral type. My class has an "operator int()". Grand.
    >>
    >> Note that the "poo" object is const. If I make the poo
    >> object non-const, then the above code compiles. BUT WHAT
    >> THE HELL DIFFERENCE DOES IT MAKE IF IT'S CONST!
    >>
    >> Some enlightenment please,

    >
    >
    > operator const int()



    That was my first thought.

    The bleeding thing still doesn't work!

    The words "compiler bug" are coming to mind...

    Anyway,

    the operator int() returns by *value*, so it would make no
    difference whatsoever if the object was const or not.

    The only reason I can see of being able to define both:

    operator int()

    and

    operator const int()

    is to have separate routines that work differently on const
    objects Vs normal objects.

    I could have the program written five times already if I
    didn't have to deal with this bullshit.

    Right now, I'm getting around it via:

    Blah temp(poo);

    switch (temp)


    That's until I figure out what the hell's going on!


    -JKop

    -JKop
    JKop, Sep 18, 2004
    #3
  4. JKop wrote:
    > G++ gives the most un-informative, cryptic, BULLSHIT errors
    > statements.
    >
    > I'm writing a program at the moment and I have to finish it
    > real soon. The problem I'm having is illustrated in the
    > following:
    >
    > class Blah
    > {
    > private:
    >
    > int k;
    >
    > public:
    >
    > operator int()



    // Means it doesn't modify k
    operator int() const


    // Also a default constructor is needed


    > {
    > return k;
    > }
    >
    > };
    >
    >
    > int main()
    > {
    > Blah const poo;
    >
    > switch (poo)
    > {
    > case 1:
    > ;
    > }
    >
    > }
    >
    >
    > The yokie that goes in a switch statement has to be an
    > integral type. My class has an "operator int()". Grand.
    >
    > Note that the "poo" object is const. If I make the poo
    > object non-const, then the above code compiles. BUT WHAT
    > THE HELL DIFFERENCE DOES IT MAKE IF IT'S CONST!
    >
    > Some enlightenment please,
    >
    > -JKop




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Sep 18, 2004
    #4
  5. * JKop:
    >
    > [swear words]


    The problem is trivial and the posting excessive: stop trolling.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Sep 18, 2004
    #5
  6. JKop

    JKop Guest

    Ioannis Vranos posted:

    > operator int() const



    This is me shaking your virtual hand:

    *shakes virtual hand*

    Hallileujah (or however you spell it!)


    Thanks a lot Ioannis.


    -JKop
    JKop, Sep 18, 2004
    #6
  7. JKop

    JKop Guest

    Alf P. Steinbach posted:

    > * JKop:
    >>
    >> [swear words]

    >
    > The problem is trivial and the posting excessive: stop

    trolling.
    >


    Subjective, asshole.


    -JKop
    JKop, Sep 18, 2004
    #7
  8. JKop

    Greg Comeau Guest

    In article <AC03d.29627$>,
    JKop <> wrote:
    >G++ gives the most un-informative, cryptic, BULLSHIT errors
    >statements.
    >
    >I'm writing a program at the moment and I have to finish it
    >real soon. The problem I'm having is illustrated in the
    >following:
    >
    >class Blah
    >{
    >private:
    >
    > int k;
    >
    >public:
    >
    > operator int()
    > {
    > return k;
    > }
    >
    >};
    >
    >
    >int main()
    >{
    > Blah const poo;
    >
    > switch (poo)
    > {
    > case 1:
    > ;
    > }
    >
    >}
    >
    >
    >The yokie that goes in a switch statement has to be an
    >integral type. My class has an "operator int()". Grand.
    >
    >Note that the "poo" object is const. If I make the poo
    >object non-const, then the above code compiles. BUT WHAT
    >THE HELL DIFFERENCE DOES IT MAKE IF IT'S CONST!
    >
    >Some enlightenment please,


    Here's the results from Comeau C++ (hint hint) which hopefully helps:

    G:\tmp>como --A --vc71 cct.cpp
    Comeau C/C++ 4.3.4.1 (May 29 2004 23:08:11) for MS_WINDOWS_x86
    Copyright 1988-2004 Comeau Computing. All rights reserved.
    MODE:strict errors C++

    "cct.cpp", line 20: error: const variable "poo" requires an initializer --
    class "Blah" has no explicitly declared default constructor
    Blah const poo;
    ^

    "cct.cpp", line 22: error: expression must have integral or enum type
    switch (poo)
    ^

    "cct.cpp", line 22: warning: variable "poo" is used before its value is set
    switch (poo)
    ^

    2 errors detected in the compilation of "cct.cpp".
    --
    Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
    Greg Comeau, Sep 19, 2004
    #8
  9. JKop

    Old Wolf Guest

    (Greg Comeau) wrote:
    > JKop <> wrote:
    >
    > >G++ gives the most un-informative, cryptic, BULLSHIT errors
    > >statements.
    > >
    > >class Blah
    > >{
    > > int k;
    > > operator int() { return k; }
    > >};
    > >
    > >int main()
    > >{
    > > Blah const poo;
    > >
    > > switch (poo)
    > >
    > >Note that the "poo" object is const. If I make the poo
    > >object non-const, then the above code compiles. BUT WHAT
    > >THE HELL DIFFERENCE DOES IT MAKE IF IT'S CONST!

    >
    > Here's the results from Comeau C++ (hint hint) which hopefully helps:


    This guy refuses to pay for software on principle, so you'll
    be lucky..

    > "cct.cpp", line 22: error: expression must have integral or enum type
    > switch (poo)
    > ^

    Interestingly, g++'s error message is:
    error: passing `const Blah' as `this' argument of
    `Blah::eek:perator int()' discards qualifiers

    ie. it seems that g++ selected 'operator int' and then noted that
    you can't call a non-const function for a const object (which
    was the OP's problem). Your compiler seems to have not selected
    this function at all for that reason (so IMHO in this
    particular case, g++'s error message was more informative).
    Comments?
    Old Wolf, Sep 19, 2004
    #9
  10. JKop

    Greg Comeau Guest

    In article <>,
    Old Wolf <> wrote:
    > (Greg Comeau) wrote:
    >> JKop <> wrote:
    >>
    >> >G++ gives the most un-informative, cryptic, BULLSHIT errors
    >> >statements.
    >> >
    >> >class Blah
    >> >{
    >> > int k;
    >> > operator int() { return k; }
    >> >};
    >> >
    >> >int main()
    >> >{
    >> > Blah const poo;
    >> >
    >> > switch (poo)
    >> >
    >> >Note that the "poo" object is const. If I make the poo
    >> >object non-const, then the above code compiles. BUT WHAT
    >> >THE HELL DIFFERENCE DOES IT MAKE IF IT'S CONST!

    >>
    >> Here's the results from Comeau C++ (hint hint) which hopefully helps:

    >
    >This guy refuses to pay for software on principle, so you'll
    >be lucky..
    >
    >> "cct.cpp", line 22: error: expression must have integral or enum type
    >> switch (poo)
    >> ^

    >Interestingly, g++'s error message is:
    > error: passing `const Blah' as `this' argument of
    > `Blah::eek:perator int()' discards qualifiers
    >
    >ie. it seems that g++ selected 'operator int' and then noted that
    >you can't call a non-const function for a const object (which
    >was the OP's problem). Your compiler seems to have not selected
    >this function at all for that reason (so IMHO in this
    >particular case, g++'s error message was more informative).
    >Comments?


    I'd be confused because it's telling me something about
    a function it should not have picked.
    --
    Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
    Greg Comeau, Sep 19, 2004
    #10
  11. JKop

    JKop Guest


    >> "cct.cpp", line 22: error: expression must have integral

    or enum type
    >> switch (poo) ^

    > Interestingly, g++'s error message is:
    > error: passing `const Blah' as `this' argument of
    > `Blah::eek:perator int()' discards qualifiers



    What G++ version is that?! Look at my original post, I got
    a totally different, non-informative error.

    -JKop
    JKop, Sep 20, 2004
    #11
  12. JKop <> writes:

    > >> "cct.cpp", line 22: error: expression must have integral

    > or enum type
    > >> switch (poo) ^

    > > Interestingly, g++'s error message is:
    > > error: passing `const Blah' as `this' argument of
    > > `Blah::eek:perator int()' discards qualifiers

    >
    >
    > What G++ version is that?! Look at my original post, I got
    > a totally different, non-informative error.


    A little question: Do you use 3.4?

    Kind regards,
    Nicolas

    --
    | Nicolas Pavlidis | Elvis Presly: |\ |__ |
    | Student of SE & KM | "Into the goto" | \|__| |
    | | ICQ #320057056 | |
    |-------------------University of Technology, Graz----------------|
    Nicolas Pavlidis, Sep 20, 2004
    #12
  13. JKop

    JKop Guest

    Nicolas Pavlidis posted:

    >> What G++ version is that?! Look at my original post, I got a totally
    >> different, non-informative error.

    >
    > A little question: Do you use 3.4?
    >
    > Kind regards,
    > Nicolas



    Okay could you do me a favour please?

    Hold my hand and slowly guide me through the process of downloading the
    latest version of G++.

    I remember the last time I downloaded G++, it was one of the most traumatic
    experiences of my life... to this day I still wake up in a cold sweat
    thinking of those abbreviations. Cryptic is not the word.


    Thanks,

    -JKop
    JKop, Sep 20, 2004
    #13
  14. JKop wrote:
    > Nicolas Pavlidis posted:
    >
    >
    >>>What G++ version is that?! Look at my original post, I got a totally
    >>>different, non-informative error.

    >>
    >>A little question: Do you use 3.4?
    >>
    >>Kind regards,
    >>Nicolas

    >
    >
    >
    > Okay could you do me a favour please?
    >
    > Hold my hand and slowly guide me through the process of downloading the
    > latest version of G++.
    >
    > I remember the last time I downloaded G++, it was one of the most traumatic
    > experiences of my life... to this day I still wake up in a cold sweat
    > thinking of those abbreviations. Cryptic is not the word.



    What GCC are you using, what version and in what OS?


    In Windows you may use the latest Beta of Dev-C++ at
    http://www.bloodshed.net.



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Sep 20, 2004
    #14
  15. JKop

    JKop Guest

    Ioannis Vranos posted:

    > JKop wrote:
    >> Nicolas Pavlidis posted:
    >>
    >>
    >>>>What G++ version is that?! Look at my original post, I

    got a totally
    >>>>different, non-informative error.
    >>>
    >>>A little question: Do you use 3.4?
    >>>
    >>>Kind regards,
    >>>Nicolas

    >>
    >>
    >>
    >> Okay could you do me a favour please?
    >>
    >> Hold my hand and slowly guide me through the process of

    downloading
    >> the latest version of G++.
    >>
    >> I remember the last time I downloaded G++, it was one of

    the most
    >> traumatic experiences of my life... to this day I still

    wake up in a
    >> cold sweat thinking of those abbreviations. Cryptic is

    not the word.
    >
    >
    > What GCC are you using, what version and in what OS?
    >
    >
    > In Windows you may use the latest Beta of Dev-C++ at
    > http://www.bloodshed.net.



    I hate bugs, I mean, I hate Dev C++. They've almost become
    synonyms for me. When I hear "bugs", I think "Dev C++".
    When I think "Dev C++", I think "bugs".

    Anyway, I've got the latest version of MS Visual Studio on
    its way to me... :-D

    A BETA version of Dev C++, is that for the 3rd World?


    -JKop
    JKop, Sep 20, 2004
    #15
  16. Ioannis Vranos, Sep 20, 2004
    #16
  17. JKop

    JKop Guest

    JKop, Sep 20, 2004
    #17
  18. JKop

    Old Wolf Guest

    JKop <> wrote:
    > >> "cct.cpp", line 22: error: expression must have integral

    > or enum type
    > >> switch (poo) ^

    > > Interestingly, g++'s error message is:
    > > error: passing `const Blah' as `this' argument of
    > > `Blah::eek:perator int()' discards qualifiers

    >
    > What G++ version is that?! Look at my original post, I got
    > a totally different, non-informative error.


    You never posted any error messages. This is g++ (note: lower-case
    g) 3.4.1. I got it from http://gcc.gnu.org/ . If you want a
    Windows binary then you should install Cygwin (www.cygwin.com)
    or Mingw.
    Old Wolf, Sep 20, 2004
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AceHigh

    Pelles C POLIB.EXE /EXPLODE utility

    AceHigh, Sep 23, 2005, in forum: C Programming
    Replies:
    3
    Views:
    801
    jacob navia
    Sep 25, 2005
  2. cc
    Replies:
    0
    Views:
    309
  3. cc
    Replies:
    1
    Views:
    392
    Niels Dybdahl
    Jun 22, 2005
  4. FFMG
    Replies:
    5
    Views:
    784
    Roland Pibinger
    Jun 8, 2006
  5. Replies:
    0
    Views:
    417
Loading...

Share This Page