Questions tagged [explicit-instantiation]

Explicit instantiation lets you create an instantiation of a C++ templated class or function without actually using it in your code.

Explicit instantiation lets you create an instantiation of a C++ templated class or function without actually using it in your code.

It is designed to optimize template libraries usage providing some of (mostly used) template instances in compiled binary form instead of source code form. This will reduce compile and link time for end-user applications.

Also it could be used to encapsulate template function definition in translation unit instead of included header.

136 questions
0
votes
1 answer

Does explicit template instantiation definition also suppress implicit instantiation?

I know that explicit instantiation declarations suppress following implicit instantiations. But what if there is only an explicit instantiation definition? Does it suppress following implicit instantiations also? For example: #include…
Lingxi
  • 14,579
  • 2
  • 37
  • 93
0
votes
1 answer

Friend declaration and explicit template instantiation declaration

Suppose I have a function template template void f(T) {} Then, we could have a friend declaration friend void f(int); and an explicit template instantiation declaration extern template void f(int); Are the two declarations…
Lingxi
  • 14,579
  • 2
  • 37
  • 93
0
votes
1 answer

Why am I getting "no matching function for call to '…'" with template function?

With the below code: materia.h: #ifndef MATERIA_H #define MATERIA_H class material { public: template static material* MakeMaterial(typename type::configtype, long); template void CreateNaturalForm(typename…
0
votes
1 answer

Explicit instantiation of class template not instantiating constructor

I'm working on a project in C++ and am having trouble understanding what members of a template class get explicitly instantiated when I explicitly instantiate the template class. I've written the following file, which I then compile using Visual C++…
0
votes
2 answers

Forcing the instantiation of static members in a template class

I want to use a static member in a template class to instantiate a singleton object for each class that inherits from that template class. Here is an example: #include #include struct X{ static std::vector&…
gexicide
  • 38,535
  • 21
  • 92
  • 152
0
votes
2 answers

Template undefined reference on windows with MinGW 4.8

I am using static template members in a class; the templates are instantiated in a cpp built in a software. I have a plug-in for the software that uses the name() template method in the header, but does not build the source file which contains the…
Jean-Michaël Celerier
  • 7,412
  • 3
  • 54
  • 75
0
votes
1 answer

c++ class template explicit instantiation work on macos, doesn't work on ubuntu

I'm writing some code which I want to publish as .h files and static library. The code is written using c++ template, with class declaration in .h file while definition in .cpp file. I used the "explicit instantiation" trick to make it possible to…
Fei Zhu
  • 155
  • 10
0
votes
0 answers

Spring bean field (which is instantiated explicitly) is assigned to null sometimes

One day we faced an incident that application started crashing because of the NPE. I found the place where it was crashing, but I cannot be sure why does it happen. Roughly speaking lets assume that I have a class A which appears a spring bean at…
0
votes
0 answers

C++ internal linkage with anonymous namespace: is this really as good as it gets?

In my class Foo, I need to construct an object using a helper function, and - as an arbitrary second function that helps force the structure of code - set a handler. Exposing the definition due to internal linkage seems like the only way to do this,…
Sean
  • 9,888
  • 4
  • 40
  • 43
0
votes
0 answers

linker error (unresolved symbol) with template class in DLL

I get a linker error - unresolved symbol - when using a (specialized) template class from a DLL (Visual Studio 2008 compiler). I tried to use the 'explicit template instantiation' trick described also here in Stackoverflow, but it didn't work. I…
user2454869
  • 105
  • 1
  • 11
0
votes
1 answer

explicit instantiation of a function

Why will i use explicit instantiation of a function template, for a type? If I do not use explicit instantiation of the function, the template is used to create the necessary function then what is the use of explicit instantiation? template
Suvarna Pattayil
  • 5,136
  • 5
  • 32
  • 59
0
votes
1 answer

How do you force a templatization to match a base class?

I have a template function which is explicitly instantiated for Base class, but not for Derived class. How can I force the uses that pass a Derived class (or other derived classes) to match against the Base class? Header file: class Base { }; class…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
-1
votes
1 answer

Are standard library non-type template classes explicitly instantiated?

When we have a templated class (or function) that has a non-type template parameter, how are the versions generated by the compiler? Surely it doesn't create a version for every possible value of N Suppose something like std::array ? I am…
TCD
  • 151
  • 1
  • 7
-1
votes
2 answers

Explicit instantiation of template class with templated member functions

With a class defined as follows: template class A { private: T a; public: A(T& a) : a_(a) { } template void Eval(D& arg) { // ... } }; template A; I want to explicitly…
-2
votes
1 answer

Using function templates for function overloading

I'm trying to overload a function while adhering to the DRY principle. The only difference between overloads are argument types, so I chose to use templating. I came up with essentially the following code: a.h: #ifndef A_H #define A_H #include…
1 2 3
9
10