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. Advertisements

  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. Advertisements

  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. Advertisements

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. 0to60
    Replies:
    4
    Views:
    738
    jeffc
    Nov 21, 2003
  2. Siemel Naran
    Replies:
    4
    Views:
    1,075
    Micah Cowan
    Jan 12, 2005
  3. Frederiek
    Replies:
    1
    Views:
    507
    Thomas Tutone
    Sep 14, 2006
  4. dolphin
    Replies:
    3
    Views:
    1,645
    Pete Becker
    Dec 5, 2007
  5. Peng Yu
    Replies:
    3
    Views:
    1,002
    Thomas J. Gritzan
    Oct 26, 2008
  6. Hicham Mouline
    Replies:
    0
    Views:
    642
    Hicham Mouline
    Apr 23, 2009
  7. Hicham Mouline
    Replies:
    1
    Views:
    587
    Michael DOUBEZ
    Apr 24, 2009
  8. Replies:
    1
    Views:
    447
Loading...