Topic: static_cast problem
Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Fri, 16 Mar 2001 10:57:04 GMT Raw View
In article <3A9D665D.73B42B0B@spamcop.net>, Ron Natalie says...
>
>Jean-Marc Bourguet wrote:
>>
>> The following sample code
>>
>> class foo;
>>
>> void* f();
>>
>> void g() {
>> foo* x = static_cast<foo*>(f());
>> }
>>
>> is accepted by all the compilers I've access except one which state that
>>
>> The operand of a static_cast must be a pointer to or lvalue of a complete
>> class; the actual type was foo *.
>
>> 5.2.9.10 does not explicitly forbit the target pointer type to be a pointer
>> to a complete class. I was wondering if the standard was specifying this
>> somewhere else.
>>
>I agree with your interpretation. Furthermore, I'm not sure in what context
>the statement in the error message could ever be construed as correct.
What if class foo was a derived class ? With multiple bases ?
Casting a void* wouldn't pose a problem, but cating a BaseX* to
a Derived* when Derived is incomplete at the scope of the cast
won't (might not) work. ( 5.2.9/5 ).
Michiel Salters
---
[ 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.research.att.com/~austern/csc/faq.html ]
Author: Jean-Marc Bourguet <bourguet@MailAndNews.com>
Date: Wed, 28 Feb 2001 19:20:59 GMT Raw View
The following sample code
class foo;
void* f();
void g() {
foo* x = static_cast<foo*>(f());
}
is accepted by all the compilers I've access except one which state that
The operand of a static_cast must be a pointer to or lvalue of a complete
class; the actual type was foo *.
5.2.9.10 does not explicitly forbit the target pointer type to be a pointer
to a complete class. I was wondering if the standard was specifying this
somewhere else.
-- Jean-Marc
---
[ 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.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Ron Natalie <ron@spamcop.net>
Date: Wed, 28 Feb 2001 21:25:09 GMT Raw View
Jean-Marc Bourguet wrote:
>
> The following sample code
>
> class foo;
>
> void* f();
>
> void g() {
> foo* x = static_cast<foo*>(f());
> }
>
> is accepted by all the compilers I've access except one which state that
>
> The operand of a static_cast must be a pointer to or lvalue of a complete
> class; the actual type was foo *.
>
> 5.2.9.10 does not explicitly forbit the target pointer type to be a pointer
> to a complete class. I was wondering if the standard was specifying this
> somewhere else.
>
I agree with your interpretation. Furthermore, I'm not sure in what context
the statement in the error message could ever be construed as correct.
---
[ 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.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]