I am trying to create an object and downcast it in the same line.
But I am getting errors with Child *cp= dynamic_cast <Parent *> new Parent();
#include<iostream>
using namespace std;
class Parent
{
public:
void Parent_display(){cout << "\n I am from Parent "<< endl;}
};
class Child:public Parent
{
public:
void Child_display() {cout << "\n I am from Child \n";}
};
int main()
{
Child *cp= dynamic_cast <Parent *> new Parent(); // This will throw an error
cp->Parent_display(); //Both parent and child can be accessed
cp->Child_display();