A forum for reverse engineering, OS internals and malware analysis 

Ask your beginner questions here.
 #27712  by GSnake
 Fri Jan 22, 2016 10:43 am
Hello guys.

I wrote my driver in C++ but I can't move my templates away from my main project .cpp file. If I put them in a separate file (.h / .cpp) everything blows up. It signals me about syntactic errors which are not "correct" since they compile correctly with the same structure in a user space application.

Any recommendation about this?


Examples:

template.h:
Code: Select all
template <bool reversed>
UINT32 Load(UINT32 x);
template.cpp:
Code: Select all
template <>
UINT32 Load<true>(UINT32 x) {
	return x;
}

template <>
UINT32 Load<false>(UINT32 x) {
	return _byteswap_ulong(x);
}

Thank you very much!
 #27714  by GSnake
 Fri Jan 22, 2016 4:08 pm
Ok, perfect. Thanks for that link, very informative!

The same happens if I put definition + implementation in the same header and I try to use the template in another file by including the aforementioned header...