Questions tagged [downcast]

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

589 questions
0
votes
1 answer

Is type erasure concept exist in C-language?

I wonder if type erasing techniques are used anywhere in C language. What happens in C, when type casting is done? Does it use concepts similar to type erasure and down casting? What are the main difference between type erasure and type casting?
NaveeNeo
  • 205
  • 3
  • 13
0
votes
1 answer

Issue with downcasting Picture

I am stuck with a downcasting issue with java. Here is the plot: The class MyPicture extends the abstract class BufferedImage. The point is to add a few methods to BufferedImage. Then, I have the class MyWindow which sets a user-friendly window. In…
Peyret
  • 3
  • 1
0
votes
0 answers

Initialize an array of pointers to objects using static downcasting?

My class is asking us to use static-casting in order to downcast our base pointers to derived pointers. class Inventory_Item{ //...functions } class Product : public Inventory_Item { //...functions } class Inventory_System { …
CoffeeAndCream
  • 21
  • 1
  • 1
  • 5
0
votes
1 answer

Down Casting to indirect subclass does not work?

public class A { public void printA(){ System.out.println("A"); } } public class B extends A { public void printB(){ System.out.println("B"); } } public class C…
0
votes
1 answer

Down-casting vs. multiple fields

I often read about that down-casting is a bad thing, and now that I need it, I ask myself what alternatives I have in my example: I have an Interface A Three Classes that implement Interface A: X1, X2, X3 These classes describe the same content, but…
moen
  • 73
  • 5
0
votes
0 answers

Is it possible to achieve run-time/compile-time polymorphism using downcasting?

I know that upcasting can be used to achieve run-time polymorphism in java. But I am curious about a similar possibility in case of downcasting. If polymorphism is possible in case of downcasting, then is it runtime or compiletime? The below code is…
Daisy
  • 31
  • 4
0
votes
1 answer

Automatic downcast during method calls in Java

So I have been reading this great article about polymorphysm in Java Upcasting and Downcasting in Java and I encounter "automatic downcast during method calls" which the author did not explain in the article but he mentioned its very useful when we…
MohsenFM
  • 129
  • 1
  • 13
0
votes
0 answers

CKEditor this.editables is not availble during a downcast?

This is an extract of my plugin (full version): CKEDITOR.plugins.add('dndck4', { lang: 'en', requires: 'widget', init: function (editor) { editor.widgets.add('dndck4', { dialog: 'atomProperties', pathName: 'atom', …
jcisio
  • 509
  • 1
  • 7
  • 17
0
votes
3 answers

Downcasting while calling super.clone() method

Consider the following program class A implements Cloneable { String str = null; public void set(String str) { this.str = str; } @Override public A clone() { A a = null; try { …
victini
  • 193
  • 1
  • 6
0
votes
3 answers

Not sure where to start with this

So just building an item and inventory/equipping system. My solution to doing this is to have a base Item class, then subclasses like MeleeWeapon, RangedWeapon etc. that will have more specific values and functions attached to them. My problem is…
0
votes
1 answer

c++ polymorphism: upcasting/re-downcasting and containers of base class, missing data

I'm trying to fill a vector with derived classes of animals (Dog, Cat, etc). When I take out the contents of the vector, I want to downcast them back to the derived classes. After doing dog.setLegs(4), I am getting back the correct number of legs…
mathmonkey
  • 335
  • 4
  • 15
0
votes
1 answer

MongoDb abstract collection and downcasting

I have a collection in MongoDb which contains objects which are derived from a class "FeedItemBase". When i query this collection, i return a list of FeedItemBase objects. //This is my collection property in the RepoBase abstract public…
pieperu
  • 2,662
  • 3
  • 18
  • 31
0
votes
1 answer

Downcast Domain Model to ViewModel

I have a domain model that looks like this: public class Procuct { string Name {get;set;} double Price {get;set;} } I have a repository that gets some item like so: public Domain.Product GetProduct(int id) { // (maps from my ORM model…
jleach
  • 7,410
  • 3
  • 33
  • 60
0
votes
2 answers

Need downcasting clarification

I do not quite understand how to downcast. Apparently I can not do it like this... class myType { }; class otherType : public myType { }; int main() { myType* obj = new myType; otherType* castObj = dynamic_cast(obj); …
D Maloid
  • 1
  • 3
0
votes
3 answers

to downcast elements from parent class

I am doing computer assignment with OpenGL But I am new of c++. It is very different with Java. here's I tried. class Map { private : public : short mapkind; float a = 5; Map() {} }; class Road : public Map { private : public : …
ssh
  • 49
  • 6