CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Location
    Heidelberg, Germany
    Posts
    121

    template problem

    Hi
    Here is my problem:
    Code:
    class A
    {
    public:
    // Constructor and so on....
    template <typename T>
    int func(T* const& var);
    //....
    
    // in the .cpp:
    template <typename T>
    int A::func(T* const& var) { var->DoSmth(); return 1; }
    I included the header into an other classes cpp like:
    Code:
    //class B .cpp
    void B::somefunc()
    {
      A a;
      CDoSmthClass *ds = new CDoSmthClass();
      // now I want to call class A's func
      a.func(ds);
      // The linker fails at this point saying "... unresolved external... public: int __thiscall A::func.......
    When I use the func method eg. in class A's constuctor with the CDoSmthClass it compiles without link error!!???!?

  2. #2
    Join Date
    Jun 2002
    Location
    Moscow, Russia.
    Posts
    2,176

    Re: template problem

    include implementation of a::func in header
    "Programs must be written for people to read, and only incidentally for machines to execute."

  3. #3
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: template problem

    There are many, many threads on this issue here .. try searching them here in this forum. You will find what needs to be done. In the meantime look at this FAQ - Why do I get unresolved externals with my template code?. Hope this helps. Regards.

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