kdelibs/khtml/rendering
Darin Adler
darin at apple.com
Tue May 25 18:28:44 CEST 2004
On May 25, 2004, at 9:05 AM, Michael Matz wrote:
> On Mon, 24 May 2004, Leo Savernik wrote:
>
>> - RenderCanvas* canvas() const;
>> + // Cannot use static_cast because RenderCanvas depends on
>> RenderObject.
>> + // Thus, the class hierarchy cannot be known at this point.
>> + RenderCanvas* canvas() const
>> + { return
>> reinterpret_cast<RenderCanvas*>(document()->renderer()); }
>
> Uhm, I've no idea about khtml's class hierarchy, but a
> reinterpret_cast<>
> is probably the wrongest cast to use here. What's the return type of
> renderer(), and what's it's relation to RenderCanvas? It's dynamic
> type
> _must_ be a RenderCanvas* if you ever hope the above to work, and in
> that
> case at least dynamic_cast<> will work, unlike reinterpret_cast<> which
> for instance does no base adjustment.
I'm pretty sure that what the right thing to do is to change this back
to static_cast, take this function definition out of the RenderObject
class definition itself, and put the inline function outside the class
body in render_canvas.h after the definition of RenderCanvas.
Then there's a requirement that anyone calling canvas() includes
render_canvas.h, which is probably not onerous if they plan to call any
functions on the result of canvas().
An alternative would be to make this a normal function rather than an
inline, and put it in render_object.cpp, depending on whether that has
any measurable code size or efficiency effects.
Keeping the reinterpret_cast is probably a bad idea.
-- Darin
More information about the Khtml-devel
mailing list