Jump to content
  • Advertisement
Sign in to follow this  

Polymorphism question

This topic is 4628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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->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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!