Inheritence Problem -- Constructors
I apologize if this thread has been posted before--the Search link is currently not working.
From my understanding, when you have a derived class, the constructors, by default, call the DEFAULT BASE CONSTRUCTOR.
When I try and make constructors that don't have the same number of arguements as one of the base constructors, I get an error. Something like "no constructor in Base with arguements".
This is a problem because, for example, I'm doing DirectX 9 coding. I have a class "SurfaceObject" which creates a blank blittable surface, and a (derived) class BitmapObject that contains many of the same methods, but none of the same constructors.
Eg. The BitmapObject constructors take in a filename of some sort, but the SurfaceObjects don't--they're blank.
How do I work around this? Will virtal methods or interfaces work?
Example (non-working):
Public class Base {
public Base(int x) {
System.Console.WriteLine("X: " + x);
}
}
Public class Derived : Base {
public Derived(int x, int y) { // Error: No constructor of class Base takes 2 arguements
System.Console.WriteLine("Y: " + y);
}
}