Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Novice
20 Views

template instantiation for MIC

Jump to solution

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

 

0 Kudos

Accepted Solutions
Highlighted
Novice
20 Views

 

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

View solution in original post

0 Kudos
1 Reply
Highlighted
Novice
21 Views

 

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

View solution in original post

0 Kudos