Sign in to follow this  
sipickles

Polymorphism question

Recommended Posts

Hello, I have an unexpected development which has confused me. In my GUI, I have a class cBaseWindow. My button class cButton inherits from this. When buttons are made, pointers are stored in the GUI in a parent/child relationship. To render the button:
void cBaseWindow::Update( int x, int y, sGUIVertex* VertexBuffer )
{

	x += m_x;
	y += m_y;

	if ( m_permissions.m_isVisible )
	{
		// render this window
		AddToVB( x, y, VertexBuffer );
	}

	// render the children
	int numChildren = m_children.size();
	for ( int i = numChildren - 1; i >= 0; i--)
		m_children[i]->Update( x, y, VertexBuffer );

}
This works fine for cButtons. AddToVB() is overridden by cButton in a polymorphic way. Now, I have another class, cTextButton. This inherits from cButton and has support for text labelling ( as opposed to an icon, which is cIconButton ). When I now call cBaseWindow::AddToVB(), the cTextButton calls the cButton::AddToVB() version, not the cTextButton::AddToVB() Why isnt cTextButton::AddToVB() called instead? Any ideas gratefully received... Thanks Simon

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this