- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all!
I just bumped into an incompatibility in a source code between the host and the target (mic).
Microsoft's compiler has no problem with my instantiation of templates, neither does intel's compiler for the host, but for the MIC target I get:
*MIC* function "Object::test(T value) [with T=float]" cannot be instantiated -- no template definition was supplied.
The template definition is supplied in the .cpp file but for an unknown reason, the compiler cannot find it.
in .h file:
class Object{ public: Object(); ~Object(); template<typename T> T test(T value); }; template T Object::test<float>(float value); //template instantiation
in .cpp file:
template<typename T> T Object::test(T value){ //template definition //do something with value }
Does anybody know what is going on?
I guess that I could put the definition in the header file but it would defeat the purpose of having a .cpp to hide the implementation...
Dorian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My bad! template explicit instantiation should be in the source file, not in the header!
It makes sense, since each implementation may require different instances of the template,
and it does not make sense to restrict the set of instances in the header...
Apparently, Microsoft's compiler does not mind about this this but intel's one does,
so it's best to put them in sources to have the most cross-platform code.
Dorian
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My bad! template explicit instantiation should be in the source file, not in the header!
It makes sense, since each implementation may require different instances of the template,
and it does not make sense to restrict the set of instances in the header...
Apparently, Microsoft's compiler does not mind about this this but intel's one does,
so it's best to put them in sources to have the most cross-platform code.
Dorian
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page