   Partial Specialization of Templated Class Member Function
  Hi all. Slightly tricky one here.I have a template class that has more than one template argument, for example:template< class X, int N >class Foo{public: int GetValue() const;};Now, say that I want to specialize GetValue so that it returns, say, 69 for a template argument of N = 5, but returns 42 for all other values of N. For example:Foo< char, 3 > foo1;foo1.GetValue(); // Returns 42.Foo< double, 17 > foo2;foo2.GetValue(); // Returns 42.Foo< bool, 5 > foo3;foo3.GetValue(); // Returns 69.One way that would work is to specialize the entire class for N = 5 and again for all other values, so as to provide two separate implementations of the class. For example:template< class X, int N >class Foo{public:int GetNumber() const { return 42; }};template< class X >class Foo< X, 5 >{public:int GetNumber() const { return 69; }};But I want to avoid this approach because while it works well for this simple example class with only one function, I am in practice trying to specialize a member function on a much larger class with many functions that would be unchanged by the specialization. Thus, I need a method to specialize only the member function in question, without duplicating the rest of class Foo.As far as I can determine, specializing the member function only works if it has a single template parameter, like so:template< int N >class Foo{public:int GetNumber() const { return 42; }};template < int N >int Foo< N >::GetNumber() const { return 42; }template < >int Foo< 5 >::GetNumber() const { return 69; }Can anyone explain how I can apply this logic to the case of multiple template arguments? The following code, by way of example, does not compile.template< class X, int N >class Foo{public:int GetNumber() const { return 42; }};template < class X, int N >int Foo< X, N >::GetNumber() const { return 42; }template < class X >int Foo< X, 5 >::GetNumber() const { return 69; }Any help would be greatly appreciated.   
  Seeing that you can't specialise a single function like you want, you have to move the work that the function does out into a helper class, and then make the original function call the helper:template< class X, int N > struct Helper { static int GetValue() { return 42; } };template<class X>struct Helper<X,5> { static int GetValue() { return 69; } };template< class X, int N >class Foo{public: int GetValue() const { return Helper<X,N>::GetValue(); }};Ortemplate< class X, int N > struct Helper { int GetValue() const { return 42; } };template<class X>struct Helper<X,5> { int GetValue() const { return 69; } };template< class X, int N >class Foo{public: int GetValue() const { return m_Getter.GetValue(); }private:Helper<X,N> m_Getter;};;  That solution suits my needs quite well. Many thanks!   