CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Template Class

  1. #1
    Join Date
    May 2000
    Posts
    63

    Template Class

    I would like to modify my existing class to be a template class, so that I could use it with different data formats.
    What changes do I have to make to my class to make it a template class? Are there any other things(problems) to consider when I'm using a template class?




  2. #2
    Join Date
    Nov 1999
    Location
    Austria
    Posts
    56

    Re: Template Class

    You have only to declare the template like that:

    CMultiDocTemplate* pDocTemplate;
    pDocTemplate = new CMultiDocTemplate(
    IDR_TEXTILTYPE,
    RUNTIME_CLASS(CTextilDoc),
    RUNTIME_CLASS(CMDIChildWnd), // standard MDI child frame
    RUNTIME_CLASS(CTextilView));
    AddDocTemplate(pDocTemplate);



  3. #3
    Join Date
    Jun 2000
    Posts
    351

    Example of a template class...


    // Very broad example
    template <class Type> class CExample
    {
    public:
    CExample() : m_Value(0)
    {
    }
    virtual ~CExample()
    {
    m_Value = 0;
    }
    void SetValue(const Type & rhs)
    {
    m_Value = rhs;
    }
    Type GetValue() const
    {
    return m_Value;
    }
    protected:
    Type m_Value;
    };





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