Skip to content

Instantly share code, notes, and snippets.

@MizukiSonoko
Created October 22, 2016 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MizukiSonoko/c9cfa6ff98a25224823f58d2f425d3c6 to your computer and use it in GitHub Desktop.
Save MizukiSonoko/c9cfa6ff98a25224823f58d2f425d3c6 to your computer and use it in GitHub Desktop.
#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