Is DECLARE_DYNAMIC required for abstract base classes in MFC?

I have a base class that is derived from the MFC CView class and the template class, for example:

template<class TYPE> class CMytViewT : public CView,public CMyTemplateClassT<TYPE> { DECLARE_DYNCREATE(CMyViewT<TYPE>) private: CMyViewT(); ' ' ' } IMPLEMENT_DYNCREATE(CMyViewT<TYPE>, CView) 

Now I assume that the MFC macros will be upset by the templates, and I am considering the possibility of removing the dynamic creation macros for this class and re-introducing it for each template specialization. for instance

 template<class TYPE> class CMytViewT : public CView,public CMyTemplateClassT<TYPE> { public: CMyViewT(); ' ' ' } Class CMyView : public CMyViewT<CMyClass> { DECLARE_DYNCREATE(CMyView) private: CMyView(); } IMPLEMENT_DYNCREATE(CMyView, CView) 

I am wondering if this will cause problems in the future, since any other implementations that I have seen have macros included for all intermediate classes. I don’t see that it is necessary, but did I miss something?

Change Looking at Matthew Druzers answer below, I found the following article on Microsoft for communication , which says that support for IMPLEMENT_DYNAMIC_T was removed due to an error.

+4
source share
1 answer

First, in the template, use IMPLEMENT_DYNCREATE_T(CMyViewT, {specialization}, CView) for each specialization if you want to support DECLARE_DYNCREATE and remove <TYPE> from DECLARE_DYNCREATE .

Secondly, the only problem you may encounter without using DECLARE_ * is to use the MFC macro DYNAMIC_DOWNCAST to transfer to or from CMyViewT; for which C ++ dynamic_cast is preferred.

If you plan to draw a template output for each specialization, you really do not need DECLARE_DYNCREATE in the representation of your template, just on your derivative.

+3
source

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


All Articles