Compiling templates

This is a discussion on Compiling templates within the C++ Programming forums, part of the General Programming Boards category; hi, I have a template class declared in a .h file, and the implementation in a .C file. Is it ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1

    Question Compiling templates

    hi,
    I have a template class declared in a .h file,
    and the implementation in a .C file.
    Is it at all possible to compile the source by including the .C file in the .h?
    Can a .o be created from a template at compile time?
    thanks in advance

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You can use an include directive to copy the code in the c files to the h file, and then include the h file where it is needed -

    template.h-
    //declarations and any inline definitions
    #include "template.c" //at very end of template.h

    template.c-
    //definitions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. Questions about Templates
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2005, 12:22 AM
  3. templates and inheritance problem
    By kuhnmi in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2004, 03:46 AM
  4. When and when not to use templates
    By *ClownPimp* in forum C++ Programming
    Replies: 7
    Last Post: 07-20-2003, 10:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21