J
jrx
I've got my_error exception type, defined as:
class my_error : public std::runtime_error {
public:
my_error(const std::string& msg) : std::runtime_error(msg) {}
};
Then, I've got Wrapper class, that wraps my classes. I create it:
Wrapper<my_error> my_error_wrapper;
my_error_wrapper.addMethod(&my_error::what);
The template method addMethod looks like:
template <class T>
class Wrapper {
public:
[...]
template <class Result>
void addMethod(Result (T::*method)()) {
}
};
The problem is, that.. it doesn't work. It appears that, my_error::what
has the type
const char* (std::runtime_error::*)() const
not:
const char* (my_error::*)() const
Quite tricky, because std::runtime_error also derives what() from
std::exception.
Is there any way to give pointer to such method as an argument?
Except form:
template <class Result, class Base>
void addMethod(Result (Base::*method)()) {
STATIC_ASSERT(is_derived<Base,T>::value);
}
Another question:
Is it possible to obtain method type in some way like:
template <class Method>
void addMethod(Method m_ptr) {
}
I know there is something like "function type" used e.g. in
boost::signals to write:
boost::signal<void (const char*)> my_signal;
Is there something like that for methods?
thanks in advance
JRX
class my_error : public std::runtime_error {
public:
my_error(const std::string& msg) : std::runtime_error(msg) {}
};
Then, I've got Wrapper class, that wraps my classes. I create it:
Wrapper<my_error> my_error_wrapper;
my_error_wrapper.addMethod(&my_error::what);
The template method addMethod looks like:
template <class T>
class Wrapper {
public:
[...]
template <class Result>
void addMethod(Result (T::*method)()) {
}
};
The problem is, that.. it doesn't work. It appears that, my_error::what
has the type
const char* (std::runtime_error::*)() const
not:
const char* (my_error::*)() const
Quite tricky, because std::runtime_error also derives what() from
std::exception.
Is there any way to give pointer to such method as an argument?
Except form:
template <class Result, class Base>
void addMethod(Result (Base::*method)()) {
STATIC_ASSERT(is_derived<Base,T>::value);
}
Another question:
Is it possible to obtain method type in some way like:
template <class Method>
void addMethod(Method m_ptr) {
}
I know there is something like "function type" used e.g. in
boost::signals to write:
boost::signal<void (const char*)> my_signal;
Is there something like that for methods?
thanks in advance
JRX