Using C++ separation model for function template instantiation

Discussion in 'C++' started by sonnu, Jan 19, 2009.

  1. sonnu

    sonnu Guest

    I have a func template declaration in "func_template.h" header and
    have the definition under "func_template.cpp" as shown below.


    1.0 How can I make use of the template declaration from a diffrent CPP
    file. My intention is not to expose the implementation details to the
    client code. Is this possible?
    2.0 Can I make this particular template instantiation exclusive for a
    single file, I mean I want to achieve what a "STATIC" keyword achieve
    in C for a func decl/defn.
    3.0 Can I get the list of standard compilers available which supports
    this model of template instantiation?

    //File func_template.h

    template<typename T, int size>
    T Median(T (&_m)[size]);

    template<typename T, int size>
    T Deviation(T (&_m)[size], T _val);
    //End func_template.h

    //File func_template.cpp
    template<typename T, int size> <------------As C++ standard
    documentation states, including "export" keyword gets compile error
    T Median(T (&_m)[size])
    //Do something
    return _m[1];

    template<typename T, int size>
    T Deviation(T (&_m)[size], T _val)
    if(size > 0)
    //do something
    return T(0);

    //File consumer_temp.cpp

    #include "func_template.h"

    int main(int argc, char* argv[], char** _environ)

    int rc = -1;

    int trng_data[4] = {1,2,3,4,5};
    int lol = Median(trng_data); <--------- Gives me Linking Error
    under VS2005 compiler????


    sonnu, Jan 19, 2009
    1. Advertisements

  2. sonnu

    Kai-Uwe Bux Guest

    Only if you use "export".

    As far as I know, only Comeau supports export.



    Kai-Uwe Bux
    Kai-Uwe Bux, Jan 19, 2009
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.