All Questions
Tagged with inheritance casting
643
questions
0
votes
0
answers
14
views
Declaring an interface property as a derived type [duplicate]
Currently I have a series of services/repos that are allowing a generic of a custom type. I want to add a generic list to that interface such that when a class inherits the interface it can apply a ...
0
votes
0
answers
86
views
Is it possible to overload casting from base class to derived class in c++?
Is it possible to overload casting to derived types from base type for purposes of checking whether such casts are ok?
I am aware of the existence of dynamic_cast, which essentially does the same ...
-1
votes
2
answers
72
views
How do you cast an generic class into an generic class of object? [closed]
let's say that you have 2 classes:
public abstract class Foo<T> {
public abstract T DoSomething();
}
public class FooInt : Foo<int> {
public override int DoSomething() {
...
0
votes
3
answers
103
views
Check if object of base class came from subclass [duplicate]
I have a base class and a bunch of subclasses of it.
I have an object of base class and I know that it was an instance of one of the subclasses before, but it was casted to the base class.
I want to ...
0
votes
0
answers
124
views
MyPy Type Check Error: No attribute found in Base class for subclass methods
I'm facing an issue with MyPy type checking, and I would appreciate some guidance on resolving it. I have a base class Base and two subclasses Sub1 and Sub2. Each subclass has its own methods (b and c,...
1
vote
1
answer
146
views
Interface Implementation and Casting in C#
I'm facing a conceptual challenge with interfaces in C#. As I understand, interfaces act as contracts, and any class that implements an interface agrees to adhere to that contract. Given this, I'm ...
0
votes
2
answers
46
views
C# Manipulate unknown child
How can I modify an object without knowing the exact type.
I have problem with accessing a child's elements in a function not knowing its exact type.
This is my example. I tried explicit and implicit ...
0
votes
0
answers
73
views
Inheritance hierarchy casting for on-demand allocating pointers
I am working on an asset management library. One of its major features are Lazy and Firm pointers that delegate asset loading and construction to the reference counter it retrieved from the asset ...
1
vote
3
answers
82
views
Can someone please explain this Java upcasting behavior I am little confused?
In the code given below when we are trying to initiate object of type A by calling the constructor of a child class when we print x.i java refers to the parent class attribute and why when called ...
0
votes
1
answer
86
views
Explicit Cast From Type to Not Implemented Interface Compiles but Fails in Runtime [duplicate]
I have a class and an interface as follows:
internal class DoStuff
{
public int X { get; }
public void Do() => WriteLine(X);
public DoStuff(int X) => this.X = X;
}
internal ...
1
vote
2
answers
82
views
SuperClass can be a type of its SubClasses?
in the below codes, What is exact type of n1 variable?
fun main() {
var n1: Number = 758.3
var n2: Double = n1
if (n1 is Double) {
println("Double")
} else if (...
0
votes
2
answers
55
views
Reasoning Behind this Java Behaviour [duplicate]
CONTEXT
say we have a class inheritance structure like this
class A {
int z = 10;
public void display() {
System.out.println("A's z is " + z);
}
}
class B extends A {
...
2
votes
0
answers
87
views
Best practices on typecasting references using dynamic cast
I need to implement a class that inherits from a purely virtual parent and one of the members I need to code is operator+=. But I actually need 2 different versions of this operator - one accepts the ...
0
votes
1
answer
142
views
When typecasting an child class's object to parent class, what happens with the variables of the object?
class HelloWorld
{
public static void main(String[] args)
{
A a = new B();
System.out.println(a.getX());
a.show();
}
}
class A {
int x = 10;
...
0
votes
2
answers
317
views
Is upcasting really a casting?
I am confused about the term upcasting in c++ (for example here). Is it really a casting? For example when I cast a an int to a double, I expect the casted type to behave exactly as a double. However, ...