Created
April 18, 2014 01:13
-
-
Save if1live/11019962 to your computer and use it in GitHub Desktop.
member method for specific class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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