Can a custom MFC window/dialog be a class template instantiation?
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-06-09T10:16:16Z
Indexed on
2010/06/10
8:12 UTC
Read the original article
Hit count: 222
There's a bunch of special macros that MFC uses when creating dialogs, and in my quick tests I'm getting weird errors trying to compile a template dialog class. Is this likely to be a big pain to achieve?
Here's what I tried:
MyDlg.h
template <class W>
class CMyDlg : public CDialog
{
typedef CDialog super;
DECLARE_DYNAMIC(CMyDlg <W>)
public:
CMyDlg (CWnd* pParent); // standard constructor
virtual ~CMyDlg ();
// Dialog Data
enum { IDD = IDD_MYDLG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
private:
W *m_pWidget; //W will always be a CDialog
};
IMPLEMENT_DYNAMIC(CMyDlg<W>, super) <-------------------
template <class W>
CMyDlg<W>::CMyDlg(CWnd* pParent)
: super(CMyDlg::IDD, pParent)
{
m_pWidget = new W(this);
}
I get a whole bunch of errors but main one appears to be:
error C2955: 'CMyDlg' : use of class template requires template argument list
I tried using some specialised template versions of macros but it doesn't help much, other errors change but this one remains. Note my code is all in one file, since C++ templates don't like .h/.cpp like normal.
I'm assuming someone must have done this in the past, possibly creating custom versions of macros, but I can't find it by searching, since 'template' has other meanings.
© Stack Overflow or respective owner