How to keep static polymorphic objects in vector? [message #1843467] |
Sat, 31 July 2021 06:24 |
kate necon Messages: 2 Registered: January 2021 |
Junior Member |
|
|
Hello everyone!
I designed my program using of Curiously recurring template pattern. I have BaseComponent<T> class and about 100 classes that are deriving from it. I want to init objects of these classes in runtime and store these objects in a vector in a specific order. Then go through this vector and call the BaseComponent<T> interface for each of them. Since I can't have vector<BaseComponent*> I added Component class. So the hierarchy is following: Component -> BaseComponent<T> -> other classes. It allows me to keep objects in specific order with vector<Component*>. But then these objects can't be cast to BaseComponent and don't have interface I required. I can use virtual function but it kills the whole idea of CRTP (and performance too). I did measurements and in my case, the use of virtual functions is super bad.
In brief: I want to have BaseComponent<T> in a specific order and use that interface without virtual functions. Does someone have advice on how can I achieve that?showbox speed test
[Updated on: Tue, 03 August 2021 13:15] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03246 seconds