How do you instantiate a template member function of a template class without making a dummy call to it?
So imagine a header: class.h
#pragma once
template<class T>
class A {
public:
template<class R>
T b(R r);
};
class.cc
#include <limits>
#include "class.h"
template<class T> template<class R> T A<T>::b(R r)
{
/* Some code */
return std::numeric_limits<R>::max() - r;
}
void dummy()
{
A<int> a;
a.b<short>(2);
}
And some test file:
#include <iostream>
#include "class.h"
using namespace std;
int main(){
A<int> a{};
auto ans = a.b<short>(2);
cout << ans << " " << sizeof(ans) << endl;
}
How do I force the compiler to compile A<int>::b<short>(short)
without calling it in class.cc (and thus having a dummy function laying around) or putting everything in the header (and having to recompile alot of code all the time).
I've tried different forms of template A<int>;
and template <> template <> int A<int>::b(short)
in the cc-file but I can't make up the right syntax.