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