explicit specialization

Apr 25, 2013 at 7:37am
error C2912: explicit specialization; 'void bdi<box>(box &,box &)' is not a specialization of a function template.


1
2
  template <typename T> T bdi(T a, T b);
  template <> void bdi<box>(box & a, box & b);


box is a struct type. And where wrong?
Apr 25, 2013 at 7:53am
Functions have overloading.
void bdi( box & a, box & b );
Apr 25, 2013 at 8:16am
i found it. the return type and argument problem.
Last edited on Apr 25, 2013 at 8:29am
Apr 25, 2013 at 8:29am
I would've thought it's because you're passing a reference in your attempt at a specialisation.
Apr 25, 2013 at 8:35am
it's because the T should be box&, and in <> i give "box", so it's not consistent.
another problem is that the return type, explicit and original template should be consistent, in my opinion.

so
template <typename T> T bdi(T, T);
template <> box& bdi<box&>(box& a, box& b);

or
template <typename T> T bdi(T&, T&);
template <> box bdi<box>(box&, box&);
:)
Last edited on Apr 25, 2013 at 8:37am
Apr 25, 2013 at 8:38am
Overload, don't specialize:

1
2
template <typename T> T bdi(T a, T b);
void bdi(box & a, box & b);


http://www.cplusplus.com/forum/beginner/100227/#msg538872
Apr 25, 2013 at 8:49am
ok, i'll check it later, dinner time :)
Topic archived. No new replies allowed.