#include #if 0 //VS only version class CConstraint { public: template void Verify(int position, int* constraints) { std::cout << "444" << std::endl; } //error: explicit specialization in non-namespace scope class CConstraint //error: template-id Verify in declaration of primary template template <> void Verify(int, int*) { std::cout << "555" << std::endl; } }; #else //Both VS + g++ template struct identity { typedef T type; }; class CConstraint { public: template void Verify(int position, int* constraints); private: template void Verify(int, int*, identity); void Verify(int, int*, identity); void Verify(int, int*, identity); }; template void CConstraint::Verify(int position, int* constraints) { Verify(position, constraints, identity()); } template void CConstraint::Verify(int, int*, identity) { std::cout << "111" << std::endl; } void CConstraint::Verify(int, int*, identity) { std::cout << "222" << std::endl; } void CConstraint::Verify(int, int*, identity) { std::cout << "333" << std::endl; } #endif int main() { int arg = 100; CConstraint obj; obj.Verify(100, &arg); //222 obj.Verify(100, &arg); //111 obj.Verify(100, &arg); //333 CConstraint obj2; obj2.Verify(100, &arg); //222 obj2.Verify(100, &arg); //111 obj2.Verify(100, &arg); //333 return 0; }