template <typename X> struct Foo
{
template <typename Y> void bar(Y)
{}
};
Template specialization.
Example:
Your mission, should you choose to accept it, is to explain to me how to write a specialized version of Foo<X>::bar that takes an int.
wouldn't it just be
template <typename X> struct Foo
{
template <typename Y> void bar(Y)
{}
template <int Y> void bar(Y)
{}
};
Cheers
Chris
template <typename X> struct Foo
{
template <typename Y> void bar(Y)
{}
template <int Y> void bar(Y)
{}
};
Cheers
Chris
I wish. Template specialization isn't allowed to occur inside a class for some strange reason.
Do you need to specialise it instead of just overloading between a template and int?
Enigma
template <typename X> struct Foo{ template <typename Y> void bar(Y) { } void bar(int);};template <typename X>void Foo<X>::bar(int){}
Enigma
Basically its not possiable so your only solutions is to overload that member function for ints e.g.
int the version will always be invoked when an int is used,
however you can specialize a member function of specialized class template e.g.
template <typename X>struct Foo { template <typename Y> void bar(Y) {} void bar(int) {}};
int the version will always be invoked when an int is used,
however you can specialize a member function of specialized class template e.g.
#include <iostream>template <typename X>struct Foo { template <typename Y> void bar(Y);};template <>template <>void Foo<double>::bar(int) { std::cout << "hi\n"; }int main() { Foo<double> b; b.bar(10);}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement