Abstract base class for derived classes with functions that have a return type of the derived class
By : Bethie
Date : March 29 2020, 07:55 AM
Any of those help When a virtual function returns a pointer or reference to a class, a class which inherits from the base class and overrides the function is allowed to change the return type to a pointer or reference to a class which is derived from the original return type. You can't return base by value as it is abstract so you can't actually create one by itself.
|
C# : Override a property and return a derived type
By : Hadas David
Date : March 29 2020, 07:55 AM
wish helps you Let's say I have a class A with the property "Details" that return an instance of class B. , Maybe you can try generics, something like this: code :
public class A<T> where T : B
{
public T Details { get; set; }
}
public class Aext : A<Bext>
{
}
public class B
{
}
public class Bext : B
{
}
|
C# Possible to override a return type on derived classes?
By : Ilkay Bülbül
Date : March 29 2020, 07:55 AM
wish help you to fix your issue , Short answer is no. Think of it, how will you use it later? code :
base b = new derivedc ()
class base<T>{
....
public virtual T name();
....
}
class deriveda : base<string>{
....
public override string name();
....
}
class derivedb : base<string>{
....
public override string name();
....
}
class derivedc : base<foo>{
....
public override foo name();
....
}
|
How to override method with derived return type in C#?
By : Mahil Arasan
Date : March 29 2020, 07:55 AM
To fix this issue I want to override a virtual method with a derived class type. What's the current best way to do this? So far I've found two approaches: , You could make the base class generic:
|
When called on a derived class, have a generic method defined in base class return derived class type in Java
By : noe041
Date : March 29 2020, 07:55 AM
around this issue You will just need to type cast it to the Generic type T in the RootEntity.save() method.
|