R
R
rsatarov2018-05-05 09:44:46
OOP
rsatarov, 2018-05-05 09:44:46

How to make std::array distinguish between parent and child?

Let's say there is a class Example and a successor ExampleDerived. How, when placing both of them in std::array, how to make the child call exactly its versions of the methods, and not the parent ones? Can this only be done manually? Or dancing with virtual?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2018-05-05
@res2001

Dancing with virtual. That's why they were invented.
There is also the question of how exactly you place objects in a std::array and what kind of objects they are. In your case, you need to put either references or pointers (smart) in the array, otherwise you risk catching problems.

C
Codebaker, 2018-05-05
@Codebaker

This can be done with CRTP

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question