Is it good to compare pointers returned by the RUNTIME_CLASS () macro?

I have a function that takes a list of pointers CRuntimeClassto customize the view. I would like to return without any action if a function is called with a list of the same classes that are already configured. Saving pointer values ​​and comparing them on the next call is currently working, but I want to check that this is a legal thing, and not something that just happens. Maybe my doc-search-fu is missing, but I can’t find it anywhere, which guarantees that the pointer value returned from the RUNTIME_CLASS () macro for this class will be the same for the life of the program. The closest I could find is in the docs forCObject::GetRuntimeClass() :

There is one CRuntimeClass structure for each class derived from CObject.

This means that the value of the pointer should not change, but it certainly will not indicate it. Does anyone have anything more specific in this regard? Or is there a better way to compare CRuntimeClasses?

+3
source share
2 answers

Taking peek at afx.hplus a bit of debugging shows that it RUNTIME_CLASS()returns a pointer to a static member: static CRuntimeClass class##class_name(as seen from the macro definition DECLARE_DYNAMIC(class_name)).

Since the element is static, the pointer to it does not change at runtime. In other words, staticis your guarantee.

+1
source

, . CObject:: IsKindOf().

+2

Source: https://habr.com/ru/post/1750111/


All Articles