Questions tagged [downcast]

Downcasting permits an object of a superclass type to be treated as an object of any subclass type.

589 questions
3
votes
2 answers

Downcast set of type X that are subclass of of Y

Note: although the question has a CoreData example, it's not related to CoreData, it's just an example We are working on a Swift project with CoreData as a caching layer. We make use of Notifications in our mainViewController a lot to listen to the…
Ennabah
  • 2,303
  • 2
  • 20
  • 39
3
votes
1 answer

How to downcast in Typescript?

How do I downcast in typescript? const x: {a: number, b: number} = {a: 1, b: 2}; const y: {b: number} = x; // upcast const z: {a: number, b: number} = ???; // downcast I can upcast x to y, but what needs to go in ??? to downcast y…
Paul Draper
  • 78,542
  • 46
  • 206
  • 285
3
votes
6 answers

Forced Downcasting in Java

I want to force a downcast on a object what can't be down casted and was wondering what the right approach would be. The use case is that I have a list of rules that are checked and what will generate a list of failed rule. A failed rule is a…
Meindert
  • 384
  • 2
  • 9
3
votes
1 answer

C++ Static_cast over a pointer to virtual base class

After about 6 o 7 years programming nearly exclusively on C++, I've discovered that: struct A { virtual ~A() = 0; // Abstract class }; A::~A() {} struct B : virtual A {}; int main() { A* a = new B; (void)static_cast(a); return…
ABu
  • 10,423
  • 6
  • 52
  • 103
3
votes
2 answers

Swift AnyObject Conversion

I created some test code to show the problem I am having. This compiles fine in a playground, however, when I try to put it into a project, Xcode gives the following warning: Treating a forced downcast to 'String' as optional will never produce…
Coder-256
  • 5,212
  • 2
  • 23
  • 51
3
votes
1 answer

Is there a python idiom for downcasting?

I'm writing a web-application based on the webapp2 framework. I'm using a common base exception for all the errors I'm explicitly throwing, like class MyBaseException(Exception): def __init__(self, status, code, message): …
agnul
  • 12,608
  • 14
  • 63
  • 85
3
votes
2 answers

Delphi - Down casting object does not call base method

I have a base object type : TBServiceBookings and then I've derived another object type from that : TBServiceQuotes So when my form is created I decide which object to use. In this instance I've created the derived object. if fScreenType =…
Frank Pedro
  • 198
  • 2
  • 10
3
votes
4 answers

Downcasting `vector`

I have a problem with upcasting and downcasting in my program. I have a vector that is passed to a function that expects const vector& pp. There are no problems up to here (EDIT: apparently there are! See the comments). But, now I…
Eliad
  • 894
  • 6
  • 20
3
votes
2 answers

Swift's pow() function won't accept Doubles as arguments

I created this infix operator ^^ as a substitute to using the pow function: infix operator ^^ { associativity left precedence 155 } func ^^ (left: T, right: T) -> T { return pow(left as Double, right as Double) } I…
Marcus Rossel
  • 3,196
  • 1
  • 26
  • 41
3
votes
5 answers

Is this not downcasting?

If I do double d = 34.56; int i = (int)d; Am I not "downcasting"? OR Is this term only used in terms of classes and objects? I am confused because in this case we are "downcasting" from a bigger double to a smaller int, but in case of classes, we…
Moeb
  • 10,527
  • 31
  • 84
  • 110
3
votes
1 answer

Swift, Parse and Xcode 6 beta6

My query to Parse now raises a swift compiler error in Xcode 6 beta6 (see error below). It was working fine previously (and my example is simple, and comes from Parse's documentation). I've changed one thing coming from Xcode 6 beta 6: from…
3
votes
3 answers

Are there any C++ tools that detect misuse of static_cast, dynamic_cast, and reinterpret_cast?

The answers to the following question describe the recommended usage of static_cast, dynamic_cast, and reinterpret_cast in C++: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? Do you know of any tools that can be used…
3
votes
3 answers

How to properly downcast in C# with a SWIG generated interface?

I've got a very large and mature C++ code base that I'm trying to use SWIG on to generate a C# interface for. I cannot change the actual C++ code itself but we can use whatever SWIG offers in the way of extending/updating it. I'm facing an issue…
JamesG
  • 792
  • 6
  • 12
3
votes
3 answers

Downcast element when reading from Dictionary in Swift

I'm trying to access an element a dictionary element and downcast it to a type other than AnyObject but keep getting the same compiler error: Could not find an overload for 'subscript' that accepts the supplied arguments. I know I can just do this…
Matt Donnelly
  • 417
  • 1
  • 4
  • 6
3
votes
1 answer

How to do dynamic downcasting in vb.net?

I have several classes, that all derives from SuperClass. When the classes are created, they all are put into a List(Of SuperClass). When I go through the list, i would like to downcast the SuperClass object to its baseObject, and put it into the…
eflles
  • 6,606
  • 11
  • 41
  • 55