template with static member

Discussion in 'C++' started by John Harrison, Jul 11, 2003.

  1. "Patrick McConnell" <> wrote in message
    news:bel9nm$rvk$...
    > The following code gives the link error:
    >
    > [Linker Error] Unresolved external 'C1<int>::f()' referenced from

    D:\PROGRAM
    > FILES\BORLAND\CBUILDER5\PROJECTS\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?


    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
     
    John Harrison, Jul 11, 2003
    #1
    1. Advertising

  2. "John Harrison" <> wrote in message
    news:beli5i$6ddkn$-berlin.de...
    >
    > 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)

    At least two :). EDG has its own back-ends too.

    --
    With regards,
    Michael Kochetkov.
     
    Michael Kochetkov, Jul 11, 2003
    #2
    1. Advertising

  3. The following code gives the link error:

    [Linker Error] Unresolved external 'C1<int>::f()' referenced from D:\PROGRAM
    FILES\BORLAND\CBUILDER5\PROJECTS\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;
    }
     
    Patrick McConnell, Jul 12, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frederiek
    Replies:
    1
    Views:
    391
    Thomas Tutone
    Sep 14, 2006
  2. dolphin
    Replies:
    3
    Views:
    1,363
    Pete Becker
    Dec 5, 2007
  3. Hicham Mouline
    Replies:
    0
    Views:
    441
    Hicham Mouline
    Apr 23, 2009
  4. Hicham Mouline
    Replies:
    1
    Views:
    424
    Michael DOUBEZ
    Apr 24, 2009
  5. Replies:
    1
    Views:
    300
Loading...

Share This Page