I have my code posted below and it gives this error- cannot convert from 'BaseClass' to 'DerivedFromBaseClass' But i understand why I get this error. because 'this' is BaseClass . it's not not DerivedFromBaseClass
I can get the type for the class who's derived from BaseClass by using DerivedFromBaseClass -in this case "public class C" However I don't know how to get the instance of the class.
I want to be able to get the instance of DerivedFromBaseClass inside the BaseClass. and then use it as a parameter for the constructor for NestedClass. ie- this gets the instance of the "BaseClass". I want to get the instance of the derived class "C"
public abstract class BaseClass<DerivedFromBaseClass> where DerivedFromBaseClass : BaseClass<DerivedFromBaseClass>
{
NestedClass nestedClass;
public BaseClass()
{
nestedClass = new NestedClass(this);
}
public class NestedClass
{
public NestedClass(DerivedFromBaseClass _parameter)
{
}
}
}
public class C : BaseClass<C>
{}
Sorry if this is worded bad I'm kind of new to this.