I have a base and derived class, as follows:
class BaseClass
{
public BaseClass(string str){ ... do stuff with str ...};
};
class DerivedClass : BaseClass
{
public Foo(string str, IntPtr ptr) { ... do stuff with str and ptr ....}
};
// Other classes can derive from BaseClass ....
Client code looks like this:
DerivedClass dc = new DerivedClass();
dc.Foo("Hello"); // <--- note no IntPtr being passed.
In these cases, the base class function is being called.
What I want is a compile time error.
How to get one?
Loading
VulpesPosted Mar 21, 2013, 12:38 PM
1. Make the Foo method in BaseClass private so it's no longer visible from DerivedClass.
2. Define an interface IFoo as follows:
You'll now only be able to call Foo(str) via an IFoo reference, not through either a BaseClass or DerivedClass reference.