Downcasting permits an object of a superclass type to be treated as an object of any subclass type.
Questions tagged [downcast]
589 questions
-3
votes
2 answers
Downcasting procedure
Can anyone please explain me if its alright to downcast this way or we SHOULD use an explicit type cast for it?
#include
using namespace std;
class base {
public:
virtual void func() { cout<<"Base \n"; }
void fun() {…

user3655742
- 21
- 2
-4
votes
1 answer
Overriding CAST operator (i think it is called downcasting)
I ma quite new to c++ and i got a small problem that is probably easy for others. I have a class A and a class B that extends class A. I have an object A, lets call it a1. I want to downcast a1 to a type B class using the syntax: "B b1=(B)a1;"
…

Alexandru Sandu
- 314
- 2
- 13
-4
votes
1 answer
Is this the correct way to implement upcasting and downcasting in the following java code?
package test;
public class Test {
public static void main(String[] args) {
A a2 = new B(); // 1
a2.display1();
a2.display();
((B) a2).display2(); // 2
((A) a2).display(); …

ekaf
- 153
- 2
- 13
-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