sealfin
2006.12.03, 09:02 AM
Okay, I'm currently putting together a UI for a game, and I've run into a minor problem - I have a 'roundedDialog' class which inherits from a foundational 'dialog' class; the dialog class has a virtual 'Render()' method, which the roundedDialog class overrides to render the pretty rounded rect which gives it its name...
The problem is that the Render() method of roundedDialog must call the Render() method of dialog to render any content of the dialog (which is private to roundedDialog); I thought the easiest way to do this would be to cast the 'this' pointer and call the method after rendering the rounded rect...
(( dialog* )this )->Render();
...except the code segfaults; now I could just add a public/protected RenderParent() method to dialog which would wrap the Render() method, and call that instead, but I'm wondering what the correct way of overcoming this problem would be (say if in the future I encounter the problem with a library I don't have the source to) - any C++ gurus care to enlighten me? :)
As my long-winded explanation probably makes little sense, I've just posted the two classes from the test-case...
class One
{
public:
virtual void Hello( void )
{
printf( "Hello!\n" );
return;
};
};
class Two : public One
{
public:
virtual void Hello( void )
{
(( One* )this )->Hello();
printf( "Whiskey tango foxtrot?\n" );
return;
};
};
The problem is that the Render() method of roundedDialog must call the Render() method of dialog to render any content of the dialog (which is private to roundedDialog); I thought the easiest way to do this would be to cast the 'this' pointer and call the method after rendering the rounded rect...
(( dialog* )this )->Render();
...except the code segfaults; now I could just add a public/protected RenderParent() method to dialog which would wrap the Render() method, and call that instead, but I'm wondering what the correct way of overcoming this problem would be (say if in the future I encounter the problem with a library I don't have the source to) - any C++ gurus care to enlighten me? :)
As my long-winded explanation probably makes little sense, I've just posted the two classes from the test-case...
class One
{
public:
virtual void Hello( void )
{
printf( "Hello!\n" );
return;
};
};
class Two : public One
{
public:
virtual void Hello( void )
{
(( One* )this )->Hello();
printf( "Whiskey tango foxtrot?\n" );
return;
};
};