D
D
Drottarutarnum2020-08-11 16:57:01
C++ / C#
Drottarutarnum, 2020-08-11 16:57:01

How to cast a child to a parent?

C++14 standard
Child inherits from Main
You can't use new

Now I do it this way, but it's not very good

Child _test = Child(true, 100);
Main &test = _test;


I would like to at least get rid of the second variable (_test )
How can I do this? Maybe there is a way to make something like a wrapper?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egorithm, 2020-08-11
@Drottarutarnum

Thanks to such a thing as upcasting, references and pointers to derived classes can be omitted explicitly from the base class. Because the base class is a subset of the derived class, and this does not seem to violate the logic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question