0

I tried something like this:

foo.h:

template< class T >
class foo
{
public:
    void bar();
private:
    void bar_impl();
};


foo.cpp:

template< type T >
void foo<T>::bar_impl()
{
    // Lengthy implementation here.
}

void foo<int>::bar()
{
    foo<int>::bar_impl();
}

void foo<float>::bar()
{
    foo<float>::bar_impl();
}

The idea here is to force instantiation of bar_impl() in foo.cpp for the possible template types and to keep the header clean.

Unfortunately, this didn't work, and after lengthy compilation I got seemingly unrelated error. Could you suggest what could be wrong here?

Michael
  • 5,775
  • 2
  • 34
  • 53
  • 2
    What you are looking for is called "explicit template instantiation" [The answers to this post should help.](https://stackoverflow.com/questions/2351148/explicit-template-instantiation-when-is-it-used) – Avi Berger Jan 25 '23 at 23:54
  • @AviBerger I'd call that a pretty good duplicate, but there is one wrinkle that I think the asker *almost* has worked out on their own. Not gold hammering it shut in case they need a bit more help with that wrinkle. – user4581301 Jan 25 '23 at 23:56

0 Answers0