Skip to content

Instantly share code, notes, and snippets.

@if1live
Created April 18, 2014 01:13
Show Gist options
  • Save if1live/11019962 to your computer and use it in GitHub Desktop.
Save if1live/11019962 to your computer and use it in GitHub Desktop.
member method for specific class
#include <iostream>
#include <type_traits>
class Foo;
class Bar;
class API {
public:
template<typename T>
void call(const T &obj) {
static_assert(std::is_same<Foo, T>::value, "allow only Foo");
printf("api call\n");
}
};
class Foo {
public:
void call() {
API api;
api.call(*this);
}
};
class Bar {
void call() {
API api;
// compile fail, if not commented
api.call(*this);
}
};
int main()
{
printf("member method for specific class\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment