How can static polymorphic objects be stored in a vector? [message #1864514] |
Wed, 20 March 2024 17:26 |
Audrey Fadel Messages: 2 Registered: March 2024 |
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 plnkgame 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?
[Updated on: Wed, 27 March 2024 13:34] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02937 seconds