09-11-2014, 04:36 AM
simple example:
header file
code file
If Foo is only used for a few values of T then by explicitly instantiating the template we can move the template implementation to separate translation unit. I want to use this to allow testing code to replace types with Mocks without having to make everything inline.
As to will it work on MSVC, that depends on how buggy it is . It was in c++98. If MSVC refuses to compile it then microsoft have a workaround that involves an anonymous namespace, a static function and some code.
header file
Code:
template <class T>
class Foo
{
bar(T a);
T x;
}
code file
Code:
template <class T>
Foo::bar(T a)
{
x = a;
}
// actual instantiation
template Foo<int>;
If Foo is only used for a few values of T then by explicitly instantiating the template we can move the template implementation to separate translation unit. I want to use this to allow testing code to replace types with Mocks without having to make everything inline.
As to will it work on MSVC, that depends on how buggy it is . It was in c++98. If MSVC refuses to compile it then microsoft have a workaround that involves an anonymous namespace, a static function and some code.