13

If I have

typedef Foo<float> Foof;

why can't I explicitly instantiate the template like this

template class Foof;

and is there a workaround apart from typing Foo<float>?

Samaursa
  • 16,527
  • 21
  • 89
  • 160
  • 1
    @Kay: I would like to explicitly instantiate `Foof` template class for `float` so that I don't get linking errors (and without including the template definitions) – Samaursa Jul 28 '12 at 23:18
  • Thanks for the -1 without explaining why :) – Samaursa Jul 28 '12 at 23:19
  • instantiation is not what you wrote in the second code that is definition¿???? what would you like to do? – Gabriel Jul 28 '12 at 23:27
  • @Gabriel: That is NOT a definition, please read this: http://stackoverflow.com/a/3534789/368599 – Samaursa Jul 28 '12 at 23:36
  • @Samaursa thanks! Did not had that quite in mind! Actually I had to explicitly instantiate function templates (cuda kernels wrappers in C++) too, when I was working with CUDA, – Gabriel Jul 30 '12 at 16:35

1 Answers1

10

and is there a workaround apart from typing Foo?

No, unfortunately there isn't. You have to type Foo<float>. As to why, see 14.7.2 clause 3 of the C++ standard for the rule (I don't know the rationale behind the rule though).

Jesse Good
  • 50,901
  • 14
  • 124
  • 166