Skip to main content
GameDev.net gamedev.net
🔒 Locked

C# overriding question

Started by PDHB Apr 28, 2004 at 2:18 PM 2 replies 400+ views
Original Post
PDHB
PDHB
Class A {... public virtual double fa() public fb() { uses fa() } ..} Class B : A {... public override fa() ...} Now suppose when I call function fb from an instance of class B, I want fb to use the original version of fa, not the new version in class B. Can I do this? how?
Behold the nascent power of Semejant!
frostburn
frostburn
guessing:


Class A
{...
public virtual double fa()
public fb()
{
uses fa()
}

..}
Class B : A
{...
public override fa()
public override fb()
{
base.fa()
}
...}
PDHB
PDHB
I''m sure that''ll work, but sometimes that will require retyping a lot of code, depending on how fa is used.

but I worry that one can override a function, and as a result change numerous other base functions that might use the original base function without meaning to.
Behold the nascent power of Semejant!
frostburn
frostburn
How's this then:


Class A
{...
protected virtual double p_fa()
{
...
}
public virtual double fa()
{
return p_fa();
}
public fb()
{
uses p_fa()
}

..}
Class B : A
{...
public override fa()
...}


Now you can override the fa() method without messing up fb().
It may look messy, but it works

[edited by - frostburn on April 28, 2004 3:51:36 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.