CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2007
    Posts
    90

    [RESOLVED] Template function and linking problem

    hello,

    i have a question regarding template function
    i have a template function in .h file.

    Code:
    template <typename T>
    int append(UINT8 *p, UINT16 type, T val)
    {
    	.................
    }
    i am using it in two classes MyClass1.cpp MyClass2.cpp
    when i included the "MyTemplate.h" in both the CPP file i get linking error. already defined !!

    can some one please tell how to fix it

    regards
    deepak

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Template function and linking problem

    Did you add a #pragma once at the beginning of the header file?

    You can also make it a public, static method of a class, but you still need the header guards.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Jan 2007
    Posts
    90

    Re: Template function and linking problem

    hello,
    it is already there!! i even added the #define too.
    i think the problem is that linker has got its definition and when it again encounters it.
    it complains "Already defined in abc.obj" file

    any other clue?

    regards
    deepak

  4. #4
    Join Date
    Jan 2007
    Posts
    90

    Re: [RESOLVED] Template function and linking problem

    solved!!

    bad and silly problem!! thanks cilu!!

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