Template specialization
Derek Parnell
derek at nomail.afraid.org
Tue Apr 10 01:14:57 PDT 2007
I've coded ...
template fill_data(T : int)
{
void fill_data(char[] raw_data, out T t)
{
t = makeInt( raw_data );
}
}
template fill_data(T : float)
{
void fill_data(char[] raw_data, out T t)
{
t = toFloat( raw_data );
}
}
and later use it like ...
struct Foo
{
float xFloat;
int xInt;
}
Foo bar;
fill_data(str, bar.xFloat);
. . .
fill_data(str, bar.xInt);
but when compiled I get these errors ...
test.d(38): template procon2.fill_data(T : int) specialization not allowed
for deduced parameter T
test.d(46): template procon2.fill_data(T : float) specialization not
allowed for deduced parameter T
What is the point of specialization if the compiler can't tell the
difference between data types? I expected that the point of using templates
is to make generic programming simpler.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
10/04/2007 6:09:58 PM
More information about the Digitalmars-d-learn
mailing list