IsKindOf detection
-
I have a class called CFileObject derived from CObject and a class called CFileTree derived from CObList. At a particular point in my program, I have an if statement that tests if an object (could be a CFileObject or CFileTree) is a CFileObject. At a point in the execution, the object is a CFileTree but when it runs the test, it returns true, saying it's a CFileObject which is incorrect. Do I need to declare my two types as being the types that they are so IsKindOf() can resolve properly?
-
I have a class called CFileObject derived from CObject and a class called CFileTree derived from CObList. At a particular point in my program, I have an if statement that tests if an object (could be a CFileObject or CFileTree) is a CFileObject. At a point in the execution, the object is a CFileTree but when it runs the test, it returns true, saying it's a CFileObject which is incorrect. Do I need to declare my two types as being the types that they are so IsKindOf() can resolve properly?
From the MSDN documentation[^]: "This function works only for classes declared with the
DECLARE_DYNAMIC
,DECLARE_DYNCREATE
, orDECLARE_SERIAL
macro. Do not use this function extensively because it defeats the C++ polymorphism feature. Use virtual functions instead." /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com -
I have a class called CFileObject derived from CObject and a class called CFileTree derived from CObList. At a particular point in my program, I have an if statement that tests if an object (could be a CFileObject or CFileTree) is a CFileObject. At a point in the execution, the object is a CFileTree but when it runs the test, it returns true, saying it's a CFileObject which is incorrect. Do I need to declare my two types as being the types that they are so IsKindOf() can resolve properly?
You could try using dynamic_cast instead. But as Ravi said, it's not good OO practice. Regards Senthil _____________________________ My Blog | My Articles | WinMacro