CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2001
    Location
    Turkey
    Posts
    173

    complicated template

    Hi Gurus,

    I have a problem with templates.
    Here is a simplified version of my problem..
    Any suggestion will be very appreciated.

    In main code I call this

    CMainEtc::OnClickOK()
    {
    CTrioGeneral tg;
    tg.HelloThere();
    }


    I gets the following error.

    error LNK2019: unresolved external symbol
    "public: __thiscall CTrioGeneral::CTrioGeneral(void)"
    (??0CTrioGeneral@@QAE@XZ) referenced in function
    "public: void __thiscall CDenemeTemplDlg::OnBnClickedTest(void)"
    (?OnBnClickedButton1@CDenemeTemplDlg@@QAEXXZ)


    Here is the simplified code

    //-----------------------------------------------------------//
    template< class TXXX, class TYYY, class TZZZ >
    class CTrio

    {
    public:
    CTrio(){};
    ~CTrio(){};

    TXXX* m_pXXX;
    TYYY* m_pYYY;
    TZZZ * m_pZZZ;
    };

    //-----------------------------------------------------------//
    template<class TYYY, class TZZZ >
    class CCouple

    {
    public:
    CCouple(){};
    ~CCouple(){};

    TYYY* m_pYYY;
    TZZZ * m_pZZZ;
    };


    //-----------------------------------------------------------//
    template< class TZZZ >
    class CSingle

    {
    public:
    CSingle(){};
    ~CSingle(){};

    TZZZ * m_pZZZ;
    };


    //----------------//
    class CBit
    {
    public:
    CBit(){};
    ~CBit(){};
    };

    //-----------------------------------------------------------//
    class CSingleEx : public CSingle<CBit>
    {
    public:
    CSingleEx(){};
    // no destructor
    };

    //-----------------------------------------------------------//
    template<class TYYY>
    class CTrioEx : public CTrio<CCouple<TYYY, CBit>, TYYY, CBit>

    {
    public:
    CTrioEx(){};
    // no destructor
    };

    //-----------------------------------------------------------//
    class CTrioGeneral : public CTrioEx<CSingleEx>
    {
    public:
    CTrioGeneral();
    // no destructor

    void HelloThere(){ AfxMessageBox("Hello There"); };
    };

  2. #2
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222
    See this Template FAQ

  3. #3
    Join Date
    Sep 2001
    Location
    Turkey
    Posts
    173

    ?

    It says that, write whole things in .H file instead of .CPP.

    I should say that, I have already written everything about template in .H file.

    Any more suggestion ?

  4. #4
    Join Date
    Sep 2001
    Location
    Turkey
    Posts
    173
    Sorry,

    I have realized that I have not implemented the constructor of last class; i.e. class CTrioGeneral()

    Last class should be like following..
    Anyway... Totally we have good(?) example of templates here
    Thanks everybody!

    //-----------------------------------------------------------//
    class CTrioGeneral : public CTrioEx<CSingleEx>
    {
    public:
    CTrioGeneral(){} ; //error here
    // no destructor

    void HelloThere(){ AfxMessageBox("Hello There"); };
    };

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