java "instanceof" in c++?
Is there a similar procedure in c++ to the java "instanceof"??
I would like to tell apart from the QObject::childs() list which widgets subclass a common base class i created for my subclassed widgets, but I haven't succeeded yet, the code I'm using right now is :
Code:
void fetchChildData
(QObject* vent
){ QObjectList childs = vent->children();
for(int i = 0 ; i < childs.size() ; i++){
displayWidget* dW = dynamic_cast<displayWidget*>(childs[i]);
if(dW!=0){
dW->fetchData();
}
fetchChildData(childs[i]);
}
}
But it won't make the trick,... Any help would be really appreciated.
Re: java "instanceof" in c++?
Have you tried QObject::inherits ?
Re: java "instanceof" in c++?
Thank you very much squidge!! It works perfectly!
By the way, and just in case I need it in a project without using Qt, is there a way to do this without using QObject::inherits?
Re: java "instanceof" in c++?
C++ does have a typeid operator. An example can be found here: http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx
However this requires RTTI to be enabled in the compiler. Typically its disabled for performance reasons.
In Qt, you can also use qobject_cast, which doesn't require RTTI support.