I have a template class as follows:
template <class T, int N>
class kernel: public std::array<T, N << 1> {
:
public:
kernel(void) : std::array<T, N << 1>{} { blah... }
template <typename... E>
kernel(const E &&... e):
std::array<T, N << 1>{{std::forward<const E>(e)...}} { blah... }
:
T write_wav(const char *filename) const { blah... }
};
In my program, I instantiate kernel<T, N>
for various values of T and N without problems, but never actually call kernel<T, N>::write_wav()
, and so the compiler does not generate a definition for it.
Thing is, I WANT the compiler to generate a definition, because I want to call kernel<T, N>::write_wav()
from my debugger (Immediate Window in VC++2015). How would I force the compiler to do so?
Thus far, the only working approach I stumbled upon is to call kernel<T, N>::write_wav()
from the constructor, and hence generate a reference to it:
kernel(void) : std::array<T, N << 1>{} { write_wav(nullptr); }
template <typename... E>
kernel(const E &&... e):
std::array<T, N << 1>{{std::forward<const E>(e)...}} { write_wav(nullptr); }
Alas, this introduces an unnecessary execution overhead. Is there a cleaner way to do this?
If I try taking the address of kernel::write_wav(), like so:
kernel(void) : std::array<T, N << 1>{} { &kernel<T, N>::write_wav; }
Then things compile fine but the member function is still not instantiated (probably because the compiler can figure out that its address has no uses).
Alternately, I tried creating a pointer to member inside the class and assigning the address to it:
T(kernel<T, N>::*write_wav_ptr)(const char *filename) const;
kernel(void) : std::array<T, N << 1>{} { write_wav_ptr = &kernel<T, N>::write_wav; }
Then things work fine (and kernel::write_wav() gets instantiated), but each instance of kernel now has an extra data member that I don't really need.