Bonjour à tous,

Ce matin, je me suis retrouvé face à un problème où le typeid m'arrange franchement bien. Je voudrais avoir votre avis sur ce tout petit bout de code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
void CEventRecognitionEngine::AddEvent(const std::string& str)
{
	BOOST_FOREACH(boost::shared_ptr<IDescriptor> ptr, m_all_events)
	{
		if (typeid(*ptr).name() == str)
		{
			descriptor_ptr ptr = CObjectFactory<IDescriptor>::Instance().Create(str);
			m_vector_vision_chain.push_back(boost::static_pointer_cast<IEventDescriptor>(ptr)->GetVisionChain());
		}
	}
}
Si vous voyez ça dans un projet :
a) Vous fuyez. Ce code est horrible.
b) Vous vous dites que c'est une partie mal écrite
c) Ca dépend du contexte, parfois le typeid est utile.

pour vos éclaircissements.