I have a question about a run time checking operation.
If a class contains a vector
of objects deriving from BPAbstract
(BPAbstract
being purely virtual) like:
typedef std::shared_ptr<BPAbstract> Ptr;
std::vector<BPAbstract::Ptr> objects_;
Now lets say that I want to group objects of a specific type in a vector
.
template<class T>
void
GetObjectsByType( std::vector<typename T::Ptr> list ) const
{
for( BPAbstract::Ptr i : objects_ )
{
// ???? ....
}
}
What would be the best implementation ? One solution would be to try to cast i
into the type T
and if the result is non null then I can add it to the list list
. I am pretty sure someone knows a better solution...
A suggestion of a better implementation of the idea would also be acceptable !