explicit-specialization

How to provide a explicit specialization to only one method in a C++ template class?

I have a template class that looks something like this: template<class T> class C { void A(); void B(); // Other stuff }; template<class T> void C<T>::A() { /* something */ } template<class T> void C<T>::B() { /* something */ } What I want is to provide an explicit specialization for only A while retaining the default fo...

Selecting an explicit specialization of a class based on a derived type

Hi I'm having problems selecting the correct version of a templated class which has an explicit specialization. I'm wanting to select a specialization using a derived class of the class used to specialize. The scenario is: #include <stdio.h> class A {}; class B: public A {}; template<typename T> class Foo { public: int FooBar(vo...

Way to set up class template with explicit instantiations

After asking this question and reading up a lot on templates, I am wondering whether the following setup for a class template makes sense. I have a class template called ResourceManager that will only be loading a few specific resources like ResourceManager<sf::Image>, ResourceManager<sf::Music>, etc. Obviously I define the class templa...

How to specialize member functions based on class template argument

What the question says. In addition, is it possible to do this inline? Here is a small example just to give an idea... template<typename T> class Foo { public: Foo() :z(0.0) {} void do( const Foo<T> &f ) { z = f.z; } // specialize 'do' for Foo<int>, possible inline? private: T z; }; ...

Explicit Instantiation

This was motivated by this article (page 5) template<class T> T const &f(T const &a, T const &b){ return (a > b ? a : b); } template int const &f<int>(int const &, int const &); int main(){ int x = 0, y = 0; short s = 0; f(x, y); // OK f(x, s); // Is this call well-formed? } Is the call 'f(x, s)' well-fo...

Normal function not overwriting template function.

Hi, I have to use an external library, but am getting a "multiple definition error" from following template function and its explicit specialization, if it gets called with a std::string. template <typename T> void foo(T& value); template <> void foo(std::string& value); even if I change the 2nd function to void foo(std::string& va...

Function Templates - Explicit specialisation vs Global Functions (C++)

I know that Function Templates are used so as to make the functions portable and so that they could be used with any data types. Also Explicit Specialization of templates is done if we have a more efficient implementation for a specific data type. But then instead of Explicit Specialization we could also just code a Nontemplate Functio...

Why do I get missing symbols for an explicit template specialization in a static library?

If I compile the following code: // // g++ static.cpp -o static.o // ar rcs libstatic.a static.o // #include <iostream> template < typename T > struct TemplatedClass { void Test( T value ) { std::cout << "Foobar was: " << value << std::endl; } }; template struct TemplatedClass < long >; I get a static library and if I run ...