optional/overloaded member function template parameter
-
Is there any way to achieve the following syntax:
typedef int nothrow;
class my_class {
public:
template<typename T> void *search(int what);
};template<typename T> void *my_class::search(int what) {throw "error";}
template<> void *my_class::search<nothrow>(int what) {return 0;}
int main() {
my_class c;
c.search<nothrow>(42); // OK!
c.search(42); // not OK
}MSVC8 "could not deduce the template argument for 'T'". I tried changing the declaration to
template<typename T = void> void *search(int what);
but unfortunately "default template arguments are only allowed on class templates." Thanks for your time. -
Is there any way to achieve the following syntax:
typedef int nothrow;
class my_class {
public:
template<typename T> void *search(int what);
};template<typename T> void *my_class::search(int what) {throw "error";}
template<> void *my_class::search<nothrow>(int what) {return 0;}
int main() {
my_class c;
c.search<nothrow>(42); // OK!
c.search(42); // not OK
}MSVC8 "could not deduce the template argument for 'T'". I tried changing the declaration to
template<typename T = void> void *search(int what);
but unfortunately "default template arguments are only allowed on class templates." Thanks for your time.anyone?