Questions tagged [upcasting]

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

244 questions
-4
votes
1 answer

java cannot upcast to an interface

private class EntryItr implements Iterator> { ... } private class KeyItr implements Iterator { private Iterator> itr; KeyItr(){ itr=new EntryItr(); // CANNOT CREATE } Why cannot upcast…
freestar
  • 418
  • 3
  • 18
-5
votes
1 answer

Assigning a child to a parent

I have a problem assigning a child pointer to a parent one. Here is the example: class A() {}; class B() : public A {}; class C() { B* b; C() { b = new B(); } B* GetB() { return b; } } C* c = new C(); A* a = c->GetB();…
Frion3L
  • 1,502
  • 4
  • 24
  • 34
-6
votes
1 answer

Upcast, downcasting, and hiding methods in C++

I'm writing a C++ library which needs to creates a complex object (D), but return to the user of my library a pointer to a simplified object (B) (hiding many of the methods of the complex object). I have decided to implement this by returning a…
TSG
  • 4,242
  • 9
  • 61
  • 121
1 2 3
16
17