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
1 answer
C# and WPF: Is it possible to make an automatic downcast of the sender argument based on its type inside an event handler?
Usually, I know what kind of specific control raises a certain event so I can make, inside the event handler, a reference to it by a manual downcast of its sender parameter like this (assuming that sender is a Button):
var refToSender =…

user3697206
- 47
- 4
0
votes
2 answers
Call child methods from parent list in Java
i have a Device parent class like this
class Device{
int id;
public Device(int id);
}
and some child devices
class SwitchDevice extends Device{
boolean state;
public SwitchDevice(int id);
boolean getState();
void…

user8770209
- 21
- 5
0
votes
0 answers
static_cast of "this" to another base class
Is the following use of static_cast in a constructor "safe"?
For context I'm experimenting with a Win32 window wrapper using a policy-based design. Part of it involves creating a dispatcher class by inheriting from a base dispatcher that holds a…

Robinson
- 9,666
- 16
- 71
- 115
0
votes
1 answer
Swift crash while "downcasting" to AppDelegate
I am trying to get access the to AppDelegate from NotificationContentExtension like this:
private var appDelegate = UIApplication.shared.delegate as! AppDelegate
I was thinking that the app will never crash, because it won't even launch without…

Dmytro Pashkov
- 350
- 3
- 11
0
votes
1 answer
Java: unwanted upcast of Vector to Vector
I'm building a class that manage Vector and Vector types, where StudenteLaureato extends Studente.
Before I added the method inserisciLaureati which merges Vector and Vector, everything was…

Nicola Amadio
- 149
- 2
- 11
0
votes
3 answers
C++ - faster downcasting children of a tree-node?
I have a simple hierarchy tree structure with a base class Node representing a node. A node could be of another specific type (subclassing).
class Node {
vector childs;
// simple node manipulation methods
const vector&…

huy
- 4,782
- 6
- 36
- 42
0
votes
0 answers
c++ how to downcast from upcasted derived
I have a class named "package" which is the base of the derived "shader_package".
The package instances generally get exclusively generated in a function called load. It has a pointer to package as a return parameter. Therefore I can also return…

MoustacheSpy
- 743
- 1
- 6
- 27
0
votes
1 answer
Downcasting Objective-C object to Swift type fails (silently)
This was discussed here; similar but not identical.
MyView is a Swift subclass of UIImageView. It compiles and its interface appears in the DerivedData/.../*-Swift.h file. But downcasting to it in Obj-C fails. The code:
MyView* myView =…

Andrew Duncan
- 3,553
- 4
- 28
- 55
0
votes
2 answers
ClassCastException for downcast JSONObject to JSONArray
i'm using the simple JSON library to write a match log analyzer for tf2. The code successfully gets all log IDs but cannot get to the actual log itself. The error is that
Exception in thread "main" java.lang.ClassCastException:
…

MrSoupman
- 7
- 3
0
votes
2 answers
Why does a virtual function break my casting?
I'm struggling with extending the following code:
#include
class XmlTree {};
class Base
{
protected:
int var;
public:
Base(int var) : var(var) {}
virtual ~Base() {}
};
class Derived : public Base
{
public:
void…

Dominic Hofer
- 5,751
- 4
- 18
- 23
0
votes
1 answer
Custom view downcasting not working
I have a custom view, CourseRaceButton, that extends LinearLayout and is to be displayed in a RecyclerView. The purpose of using a custom view is to embed a state control enum into each button separately, so that colours etc can be changed depending…

Richardweber32
- 168
- 2
- 16
0
votes
1 answer
finding the type of a templated derived class
I have a vector container holding pointers of a base class:
class Wrapper_base {
public:
virtual ~Wrapper_base() {}
};
template
class Wrapper : public Wrapper_base {
private:
T t_;
public:
Wrapper(const T t) : t_(t)…

Arash
- 141
- 10
0
votes
0 answers
Im trying to use typeid() but i keep getting an error C3867
I am trying to use typeid() but i keep getting an error im not sure why.
void RandomAttributes(Shape * S)
{
// pointer need for down casting
MyTriangle * triPtr;
MyRect * rectPtr;
MyCircle * circPtr;
//downcast base class pointer to derived class…

Alvaromon
- 190
- 2
- 16
0
votes
1 answer
Adding arrays of different types
Is there more elegant way of adding two arrays of different types in Swift?
My first try was to downcast an array to Any and just add it.
class BasicClass {
var name : String = ""
var number : Int = -1
init(name : String, number :…

mikro098
- 2,173
- 2
- 32
- 48
0
votes
1 answer
VersionOne Web API - How do i get all of the stories/tasks for a given epic?
I am trying to query V1 (from Excel VBA) using the http api client. I can query for a specific epic and get the data from…

SupraFun
- 1
- 2