Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > BEFORE I EXPLODE

Reply
Thread Tools

BEFORE I EXPLODE

 
 
JKop
Guest
Posts: n/a
 
      09-18-2004
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
 
Reply With Quote
 
 
 
 
Ioannis Vranos
Guest
Posts: n/a
 
      09-18-2004
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
 
Reply With Quote
 
 
 
 
JKop
Guest
Posts: n/a
 
      09-18-2004
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
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      09-18-2004
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
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      09-18-2004
* 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?
 
Reply With Quote
 
JKop
Guest
Posts: n/a
 
      09-18-2004
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
 
Reply With Quote
 
JKop
Guest
Posts: n/a
 
      09-18-2004
Alf P. Steinbach posted:

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

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

trolling.
>


Subjective, asshole.


-JKop
 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      09-19-2004
In article <AC03d.29627$(E-Mail Removed)>,
JKop <(E-Mail Removed)> 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?
 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      09-19-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Greg Comeau) wrote:
> JKop <(E-Mail Removed)> 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: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?
 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      09-19-2004
In article <(E-Mail Removed) >,
Old Wolf <(E-Mail Removed)> wrote:
>(E-Mail Removed) (Greg Comeau) wrote:
>> JKop <(E-Mail Removed)> 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: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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want feedback on C++ version of Python's explode operator k04jg02@gmail.com C++ 0 02-06-2007 04:35 PM
My Explode function(s) are too slow. FFMG C++ 5 06-08-2006 06:55 PM
Pelles C POLIB.EXE /EXPLODE utility AceHigh C Programming 3 09-25-2005 07:09 AM
explode a DVD VOB with c++ cc C++ 1 06-22-2005 08:14 AM
C++ and DVD VOB explode cc C++ 0 06-22-2005 06:49 AM



Advertisments