c++ - reinterpret_cast vector of class A to vector of class B -
say have 2 classes a
, b
, , vector of class a
below:
class { int foo; int bar; void somemethod(); }; class b { uint foo; uint bar; void someothermethod(); }; std::vector<a> va;
and want interpret va
vector of b, since int
, uint
re-interpretable.
what best practice re-interpretation? example, if want invoke someothermethod()
on va
, can ((std::vector<b> *)(&va))->someothermethod()
. best practice?
it seems me reinterpret_cast<std::vector<b> >(va).someothermethod()
not work.
in addition, working on c++03.
-- update --
sorry misinterpret of own question. yet question lot different one. created question here.
i close question soon: question can seen independent question, , think 1 of answers below enough accepted.
don't. way think can results in undefined behaviour. create new vector , copy on values.
Comments
Post a Comment