Original Post
I have a big problem, a problem I cannot solve. This function breaks with the error below. ((*m_Iter)); part. But it gets the above error and blows up in my face. Ive tryied static_cast/reinterpret_cast/dynamic_cast, but with the same result. *BOOM* Im quiet desperate and out of options... [SOLVED] I made a function that returned a IComponent* and casted it manually while reciving it. It seems to work better. [Edited by - Lipponen on August 27, 2008 1:37:45 PM]
/*Fix: This function just explodes in my face!*/
template <class T> T* TComponent(uint32 type) {
if(HasComponent(type)) {
return static_cast<T*>((*m_Iter));
}
return NULL;
};
bool CEntity::HasComponent(uint32 type) {
if(m_CompList.empty()) return false;
m_Iter=m_CompList.begin();
for( ; m_Iter!=m_CompList.end(); m_Iter++) {
if((*m_Iter)->Type()==type)
return true;
}
return false;
}
First-chance exception at 0x0041e86f in app.exe: 0xC0000005: Access violation reading location 0xcdcdcddd.
The iterator m_Iter is pointing to the right component at the return static_cast