Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Handles replacing pointers using indices

$
0
0
Lets assume we have some collections: struct A { virtual ~A(); }; struct B : A {}; struct C1 : B {}; struct C2 : B {}; struct C3 : A {}; std::vector< C1 > c1s; std::vector< C2 > c2s; std::vector< C3 > c3s; Is it now possible to create a Handle template class that access c1s, c2s, c3s via an index? Handle< C1 >, Handle< C2 > and Handle< C3 > are trivial. But is it somehow possible to cast Handle< C1 > and Handle< C2 > to Handle< B > while still accessing the right vectors (though returning B* or B&)? Similarly, is it somehow possible to cast Handle< C1 >, Handle< C2 >, Handle< C3 > and Handle< B > to Handle< A > while still accessing the right vectors (though returning A* or A&)? (Mis)using std::type_index?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>