I have several views in my app, that are almost the same, so I decided to create a CBaseView class and to not copy the code. So I have something like this:
template <class BASE_T, class BASE_DOC, class BASE_DLG>
class CBaseView : public CListView
{
DECLARE_DYNCREATE(CBaseView<BASE_T, BASE_DOC, BASE_DLG>)
void func1()
{
// GetData() is just another method in CBaseView
BASE_T oData = GetData();
...
}
void func2()
{
BASE_DOC* pDocument = (BASE_DOC*) CView::GetDocumet();
pDocument->DoSomething();
...
}
void func3()
{
...
BASE_DLG oBaseDlg();
oBaseDlg.DoModal();
...
}
}
IMPLEMENT_DYNCREATE(CBaseView<BASE_T, BASE_DOC, BASE_DLG>, CListView)
After that I want to use the CBaseView for the others views:
CMyView : public CBaseView <MyType, MyDocument, MyDlg> {...};
The problem is coming with:
DECLARE_DYNCREATE(CBaseView<BASE_T, BASE_DOC, BASE_DLG>)
and
IMPLEMENT_DYNCREATE(CBaseView<BASE_T, BASE_DOC, BASE_DLG>, CListView)
It gаve me some strange errors. I saw that I can't use this macros with a template class. Also found a similar topic, but I'm quite new in MFC (and in programming like all) and I can't rewrite it so to works for my three template arguments.
I'm worried that I tried everything I could think of and still haven't done it. I really need to find a way to do it or at least an alternative, so guys please help me!