All pastes #929029 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-03-05 14:11 UTC
rendered paste body
#include <string>

struct Foo {
  void set_str(const std::string& str) {}
  void set_str(const char* str) {}
  void easy(int str) {}
};

struct Bar {

  template <typename ValueType,typename ClassType>
  void templateMethod(void (ClassType::*)(ValueType)) {
    // Do something with the method pointer.
  }
};

    
int main() {
  Bar b;
  // Should pass pointer to set_str(const string&), but how to specify that constraint?
  b.templateMethod<>(&Foo::easy);
  b.templateMethod<const char *>(&Foo::set_str);
//   b.templateMethod<Foo>(&Foo::set_str);
}