template with static member

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick McConnell

    template with static member

    The following code gives the link error:

    [Linker Error] Unresolved external 'C1<int>::f()' referenced from D:\PROGRAM
    FILES\BORLAND\C BUILDER5\PROJEC TS\MAIN.OBJ

    Using Borland CBuilder5. If i define the body of the function f in the
    header file1.h, it links ok. I believe this is normal language behaviour
    because all the ATL libs are defined in the headers. But is there another
    way to do it so i can define my functions in the cpp file?

    file1.h:
    /////////////////////////////////
    template<class T>
    class C1
    {
    public:
    static void f();
    };
    /////////////////////////////////

    file1.cpp:
    /////////////////////////////////
    template<class T>
    void C1<T>::f()
    {
    }
    /////////////////////////////////

    main.cpp:
    /////////////////////////////////
    #include "file1.h"

    int main(int argc, char* argv[])
    {
    C1::f();
    return 0;
    }


  • John Harrison

    #2
    Re: template with static member


    "Patrick McConnell" <pmcconnell001@ epacsten.com> wrote in message
    news:bel9nm$rvk $1@news.eusc.in ter.net...[color=blue]
    > The following code gives the link error:
    >
    > [Linker Error] Unresolved external 'C1<int>::f()' referenced from[/color]
    D:\PROGRAM[color=blue]
    > FILES\BORLAND\C BUILDER5\PROJEC TS\MAIN.OBJ
    >
    > Using Borland CBuilder5. If i define the body of the function f in the
    > header file1.h, it links ok. I believe this is normal language behaviour
    > because all the ATL libs are defined in the headers. But is there another
    > way to do it so i can define my functions in the cpp file?[/color]

    No, templates must go in the header file.

    There is an export keyword that is supposed to handle this but

    a) its contrversial
    b) only one compiler supports it (and its not borland)

    john


    Comment

    • Michael Kochetkov

      #3
      Re: template with static member


      "John Harrison" <john_andronicu s@hotmail.com> wrote in message
      news:beli5i$6dd kn$1@ID-196037.news.uni-berlin.de...[color=blue]
      >
      > There is an export keyword that is supposed to handle this but
      >
      > a) its contrversial
      > b) only one compiler supports it (and its not borland)[/color]
      At least two :). EDG has its own back-ends too.

      --
      With regards,
      Michael Kochetkov.


      Comment

      Working...