GetType for class
-
Hello! I want to compare the type of an object to a class. What is the correct syntax to use? In my case, I want to know if a control is an instance of MdiClient. GetType works on the pointer, but not on the class. typeid(MdiClient) gives me error C3767. Alex
-
Hello! I want to compare the type of an object to a class. What is the correct syntax to use? In my case, I want to know if a control is an instance of MdiClient. GetType works on the pointer, but not on the class. typeid(MdiClient) gives me error C3767. Alex
if (some_ref_handle->GetType() == MdiClient::typeid)
{
//some_ref_handle references a MdiClient object!
} -
if (some_ref_handle->GetType() == MdiClient::typeid)
{
//some_ref_handle references a MdiClient object!
} -
Thank you! At first I got an error because MdiClient is a private(?) member of the class (which is not shown in the IntelliSense list). But with Windows::Forms::MdiClient::typeid it works. Alex
Cool :)
LionAM wrote:
MdiClient is a private(?) member of the class
MdiClient IS the class.
LionAM wrote:
But with Windows::Forms::MdiClient::typeid it works.
Oops - I guess I assumed "using namespace Windows::Forms;" typeid needs to know the type at compile time. You could also use something like
if (some_ref_handle->GetType() == Type::GetType("Windows::Forms::MdiClient"))
for a runtime check. Cheers, Mark
-
Cool :)
LionAM wrote:
MdiClient is a private(?) member of the class
MdiClient IS the class.
LionAM wrote:
But with Windows::Forms::MdiClient::typeid it works.
Oops - I guess I assumed "using namespace Windows::Forms;" typeid needs to know the type at compile time. You could also use something like
if (some_ref_handle->GetType() == Type::GetType("Windows::Forms::MdiClient"))
for a runtime check. Cheers, Mark
-
Hello!
::MdiClient::typeid
works, butMdiClient::typeid
gives error C3223: 'System::Windows::Forms::Form::MdiClient' : you cannot apply 'typeid' to a property AlexMdiClient is in the System::Windows::Forms namespace, not the System::Windows::Forms::Form namespace (which doesn't exist - System::Windows::Forms::Form is a class). Either of these should work:
using namespace System::Windows::Forms;
...
if (objectref->GetType() == MdiClient::typeid)or
if (objectref->GetType() == System::Windows::Forms::MdiClient::typeid)
Mark