I have a Visual Studio 2008 c++03 project where I’ve come across something like this:
//foo.hpp
namespace Foo {
template< typename T >
inline void foo( T t )
{
// do stuff...
};
}; // namespace foo
// foo.cpp
#include "foo.hpp"
namepsace Foo {
template void foo< int >();
}; // namespace Foo
//main.cpp
#include "foo.hpp"
int main(void)
{
int a = 5;
Foo::foo(a);
return 0;
}
This does create a foo.obj file that I presume contains Foo::foo< int >(), but it does not seem to affect the size of main.obj.
Does this technique work to reduce compile time of template code? Or is it actually increasing compile time because Foo::foo< int >() must now be compiled twice?
Thanks
Functionally, there is no difference.
foo.cpponly contains a declaration (no definition). The compile time is increased if you includefoo.cppin the compilation.