Created
October 22, 2016 06:08
-
-
Save MizukiSonoko/c9cfa6ff98a25224823f58d2f425d3c6 to your computer and use it in GitHub Desktop.
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 Base{ | |
public: | |
int get(){ return 1234; } | |
}; | |
class A{}; | |
class B : public Base{}; | |
template<typename T, std::enable_if_t<std::is_base_of<Base, T>::value, std::nullptr_t> = nullptr> | |
void f(T c){ | |
std::cout <<"OK:"<< c.get() << std::endl; | |
} | |
int main(){ | |
A a; | |
B b; | |
// f(1); compile error! | |
// f(a); compile error! | |
f(b); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment