Order of template specializations

Discussion in 'C++' started by Thomas Matthews, Feb 26, 2004.

  1. Hi,

    I have a templated class field:
    template <typename Value_Type>
    class Field
    {
    public:
    Value_Type value;
    };

    I want to load the value member from an std::istream.
    I want to use a special algorithm for string fields,
    but the extraction operators for all others.

    My question is: does the overloaded function have
    to be declared before the template version?

    void LoadField(Field<string>& sf, istream & inp)
    {
    // ...
    }

    template <typename Value_Type>
    void LoadField(Field<Value_Type>& vf, istream & inp)
    {
    // ...
    }

    I would like to create specializations for the
    Field<string> and place them in a different
    translation unit than the one in which Field is
    defined.

    The idea is that when somebody wants a Field<double>
    they don't get all the function declarations for
    Field<string>.

    This example was simplified from my actual code.
    My actual design is:
    Field
    ^
    |
    Typed_Field (template)
    ^
    |
    Sortable_Typed_Field

    typedef Sortable_Typed_Field<int> Integer_Field;
    typedef Sortable_Typed_Field<string> String_Field;

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
     
    Thomas Matthews, Feb 26, 2004
    #1
    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. Tseng, Ling-hua
    Replies:
    0
    Views:
    448
    Tseng, Ling-hua
    Dec 8, 2003
  2. Tom Richardson
    Replies:
    1
    Views:
    335
    Victor Bazarov
    Dec 19, 2003
  3. Imre
    Replies:
    1
    Views:
    295
    Chris Jefferson
    Feb 21, 2005
  4. Samee Zahur
    Replies:
    1
    Views:
    359
    Victor Bazarov
    Apr 29, 2005
  5. John Doe
    Replies:
    4
    Views:
    387
    John Harrison
    Sep 11, 2005
Loading...

Share This Page