C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: cannot compare base* to const derrived*

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Victor Bazarov
Guest





PostPosted: Fri Jul 25, 2003 2:27 am    Post subject: Re: cannot compare base* to const derrived* Reply with quote



"Immanuel Scholz" <einwegadresse (AT) gmx (DOT) de> wrote...
Quote:
Today, I tried the following statement and got an compiler error:


class Base {};
class Derrived : public Base {};

int main()
{
Base* b = 0;
const Derrived* d = 0;
return (b == d);
}


The compiler refuses to convert either Base* to const Derrived*
(downcast) or convert const Derrived* to Base* (constcast).

Neither cast can be made implicitly, both require explicit casts.
However, 'b' can be converted to const Base* and 'd' can be
converted to const Base*, and both are accepted. That's what
the compiler should do.

What did the compiler say? I tried this on Comeau and it gladly
accepted the code.

Quote:
But it could convert both, Base* to const Base* and const Derrived* to
const Base*.

Why refuses the compiler to resolve the casts? Is it an error within
the compiler?

Very well could be.

Quote:
I thought it is only forbidden to implicit convert one function
argument twice, but not to convert more than one argument only once?
Am I correct?

Probably. Rules of overload resolution are so many and so...
How should I put it?... murky. At least to me. I remember that
for the assignment operator the left operand is not converted.
As to other conversions, I am blanking out for a moment.

Quote:
If the compiler is right, is there a reasoning about why it is
forbidden?

I think the compiler is wrong.

Victor


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.