Downcasting permits an object of a superclass type to be treated as an object of any subclass type.
Questions tagged [downcast]
589 questions
0
votes
2 answers
What are the disadvantages of dynamic_cast in C++?
Despite the fact that dynamic_cast returns a 0 if the pointer that is being handled is of an incompatible type, why would you avoid using dynamic_cast?

Enigman
- 640
- 3
- 9
- 21
0
votes
1 answer
Handling specifics of derived classes without downcasting
Let's say I have two different types of colliders, circles and boxes, that are derived from the same base collider class. I have an entity class that contains a pointer to a collider that can be a circle collider or a box collider.
class Collider…

Freegor
- 1
0
votes
2 answers
Casting derived to base, and then casting that into another derived. Java
So I have 3 classes.
base
derived1 derived from base
derived2 derived from base
This code says that derived1 cannot be casted to derived2, even though I already casted derived1 to a base object?
base temp = (derived2)((base)derived1);
I'm trying to…

Zera42
- 2,592
- 1
- 21
- 33
0
votes
1 answer
Downcasting: tree construction
I wrote a spike solution for a basic tree building class that I created.
The Output for the first "Adding Item No {0} at the depth of {0}" is item 0 depth 0, not the expected 0,1.
It just hit me as I was writing this out. Could it be due to my down…

Omicrom
- 1
0
votes
2 answers
dynamic cast fails on downcasting from parent to child
I have the following parent child simple classes:
class BoundBases{
public:
virtual ~BoundBases() { }
};
// Rectangular Bounds for tree
class RectBounds : public BoundBases{
public:
// x, y center point
…

Saher Ahwal
- 9,015
- 32
- 84
- 152
0
votes
2 answers
Java dynamic downcasting from generic list
how i can dynamic downcast objects, with out instanceof statement?
I reading Bruce Eckel's Thinking in Java, and there using Class, and there is such a theme, but I was not approached
P.s. Sorry for my English.
public class GenericTest {
…

Jaz Brok
- 231
- 1
- 4
- 18
0
votes
1 answer
change a member method without touching the source code, downcasting?
Suppose I am using a third party project with a Class A in it. And Class A is used everywhere. Inside Class A, I am not happy with Method M1. Firstly, I don't wanna change Class A, secondly, I need A.M1() know about something in the context. (M1…

huoenter
- 512
- 3
- 16
0
votes
0 answers
can i cast metadata class type object to partial class type object?
i have something like this
[MetadataType(typeof(MetaData_Course_application))]
partial class COURSE_APPLICATION
{
}
public class MetaData_Course_application
{
[Required]
[StringLength(15, MinimumLength = 2)]
public string…

Yogseh pathak
- 61
- 1
- 1
- 5
0
votes
1 answer
Downcast to "foreign" class without data members
Consider the following code:
struct A { int m; };
struct B : A { void proc () { /* ... */ };
struct C : A { void proc () { /* ... */ };
A a;
B * b = (B *) &a;
C * c = (C *) &a;
b->proc ();
c->proc ();
Is that legal and well-defined?
Pro: A is…

JohnB
- 13,315
- 4
- 38
- 65
0
votes
2 answers
Store different (unmodifiable) types in a List
I am using two different libraries each having their own type for a point. Both types have x and y coordinates while each has also some special fields. I would like to store both types (say PointA and PointB) in a List. I can't use base-class since…

c0dehunter
- 6,412
- 16
- 77
- 139
0
votes
1 answer
Is there an expression to downcast and simultaneously access a property in F#?
In C#, in order to access a property/method I might downcast to a type and then access the property:
Fruit f = new Banana();
((Banana)f).Peel();
What is the equivalent in F#? I tried the following but the intellisense after typing the period does…

User
- 62,498
- 72
- 186
- 247
0
votes
1 answer
Downcasting double to int which rounding mode?
Which of the following rounding mode is followed by casting a double to an int?
Result of rounding input to one digit with the given rounding mode
Input HALF_EVEN
Number UP DOWN CEILING…

Rollerball
- 12,618
- 23
- 92
- 161
0
votes
2 answers
how can this downcast works:(B)super.clone()?
class A {
}
public class B extends A {
public static void main(String[] args) {
A m = new A();
B n = (B)m;
}
}
this code can not be complied. However, in the code below, this downcast works.
class A {
}
public class B extends A…

andy
- 3,951
- 9
- 29
- 40
0
votes
2 answers
C++ -- Method for Casting between different Templated versions of a class
So, I have a single templated class, B, which inherits from a non-template class A. Now, this templated version B, has a set of four valid and known template classes, call them B, B, B, B.
Currently, I am…

Nava2
- 437
- 3
- 16
0
votes
4 answers
incorrect behaviour while downcasting c++
Here's a piece of code I had written to see the behaviour during downcasting.
#include
using namespace std;
class base {
public :
void function()
{
cout << "\nInside class Base";
}
};
class derived : public base…

Sumit Das
- 1,007
- 9
- 17