• Advertisement
Sign in to follow this  

Calling a Parent Function (C#) [solved]

This topic is 4577 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

Ok last C# question for a while, promise [wink] From what I understand, C# has done away with the scope ('::') operator, so how do you call a parents class version of an overriden method? Here is what I have
[source="C#"]
	// The base class for all world objects to derive from
	public class WorldObject
	{
		// Renders the object
		public virtual void render()
		{
			... // Some general render code
		}
	}



	public class WOLevelGenerator : WorldObject
	{
		// Renders the object
		public override void render()
		{
			... // Some WOLevelGenerator specific render code
			// In C++ I would put something like this here
			// WorldObject::render();
		}
	}



Does anyone know how to do something like that in C#; basically daisy change down an inheritance hierarchy? Thanks, Matt Hughson [Edited by - matthughson on October 8, 2005 11:37:27 PM]

Share this post


Link to post
Share on other sites
Advertisement
You use the base keyword [smile]

base.render

In the case of aconstructor, you have

base(params)

Share this post


Link to post
Share on other sites
Cool thanks! Just curious, but isn't that a little ambiguous? Like what happens in an object derives from >1 classes?

Matt Hughson

Share this post


Link to post
Share on other sites
C# doesn't allow multiple inheritance (In my opinion it won't be missed [grin]); only a single base classe and an arbitrary number of interfaces can be used. (An interface is basically a collection of method that the class implementing the interface must implement.)

Here's some reading material

Share this post


Link to post
Share on other sites
Yeah now that you mention it, I remember reading that (just started this C# thing last night, so some things didn't really stick yet [wink]). They're kind of like a legitamized ADT.

Reading material... yuck! [wink]

Matt Hughson

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement