Reputation: 87
I have a template class
expof.h:
template <class T>
class ExpOf{
...
}
which I repeatedly use throughout my code for e.g. T = double
[and other classes that ExpOf
should not know anything about].
So I thought it would be a good idea to compile it once and for all [or twice...]
expofdouble.cpp:
#include "expof.h"
template class ExpOf<double>;
and declare it in a different header so it would not get compiled when expof.h is included.
expofdouble.h:
extern template ExpOf<double>;
When I compile this (clang-800.0.42.1) I get (numerous) warnings
expofdouble.h: warning: declaration does not declare anything [-Wmissing-declarations]
extern template ExpOf<double>;
^~~~~~~~~~~~~
Am I getting the desired behavior? Why the warning then? Should I do this differently?
Upvotes: 4
Views: 2682
Reputation: 168998
expofdouble.h
should contain this line:
extern template class ExpOf<double>;
Your declaration omits the class
keyword, so it doesn't actually declare anything.
(Note that you'll get the same warning with a declaration like extern int;
, which quite obviously doesn't do anything useful for you.)
Upvotes: 5