Order of template specializations

T

Thomas Matthews

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top