CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Location
    Sussex, England
    Posts
    49

    IMPLEMENT_DYNAMIC using templates

    I am wanting to use RegisterClass for a number of classes which inherit from CFormView. The classes are so similar (ie. they only differ by the dialog ID they use) that I would like to use a templated class and then call RegisterClass(CPageTemplate<IDD_THISDIALOG> for each one. I am having problems with using IMPLEMENT_DYNAMIC in achieving this. The code for the template I am having problems with looks like this.


    template<UINT iResource> class CPageTemplate : public CFormView
    {
    protected:
    CPageTemplate<iResource>(){};
    DECLARE_DYNCREATE(CPageTemplate)

    // Form Data
    public:
    enum { IDD = iResource };

    protected:
    virtual ~CPageTemplate<iResource>(){};

    };

    template<UINT iResource>
    IMPLEMENT_DYNAMIC(CPageTemplate<iResource>, CFormView)




    Any help would be appreciated.


  2. #2
    Join Date
    Apr 1999
    Posts
    383

    Re: IMPLEMENT_DYNAMIC using templates

    You will need to pass the full template class name to DECLARE_DYNCREATE:
    DECLARE_DYNCREATE(CPageTemplate<iResource&gt

    DECLARE_DYNCREATE provides the member declarations implemented by IMPLEMENT_DYNAMIC, so the class names passed to the two macros must match.

    IMPLEMENT_DYNAMIC is a macro, not a function, so the template function syntax you used for it is not appropriate. Try just:
    IMPLEMENT_DYNAMIC(CPageTemplate<iResource>, CFormView)


    IMPLEMENT_DYNAMIC uses the class names passed to it to implement member data and a member function of that class. I don't know whether it will work correctly with a template class (I don't see why not), but if not, you can write your own template version based on the originals in afx.h (around line 827).

    Dave


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured