curiouswebster
asked on
I need to enforce an interface AND have base functionality in C#
I need to force child classes to override certain virtual functions and have a certain amount of functionality in the base class.
Since I need member variables and function bodies, I can not use an abstract class. Therefore I can not use an abstract method. Then, since the best I can do is virtual functions, those can be overridden optionally in the child classes.
What I think need is a pure virtual function. Am I right?
How do I implement this in the base class? I am having trouble using the format I expected to use and have seen on the web:
public virtual void DisplayCancelOpMessage() = 0;
I get a "; expected" error from the compiler.
Thanks for the help,
newbieweb
thanks,
newbieweb
Since I need member variables and function bodies, I can not use an abstract class. Therefore I can not use an abstract method. Then, since the best I can do is virtual functions, those can be overridden optionally in the child classes.
What I think need is a pure virtual function. Am I right?
How do I implement this in the base class? I am having trouble using the format I expected to use and have seen on the web:
public virtual void DisplayCancelOpMessage() = 0;
I get a "; expected" error from the compiler.
Thanks for the help,
newbieweb
thanks,
newbieweb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
public abstract void DisplayCancelOpMessage();
How i normally solve your dilemna is having an interface which is implemented by an abstract class then provide a body for the methods or properties i need to implement then declare the others as abstract / pure virtual if you prefer this C++ term.