Guest User

Untitled

a guest
Jul 3rd, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. class Foo {
  4.     public:
  5.     void bar(){
  6.         printf("Foo::bar\n");
  7.     }
  8. };
  9.  
  10. class Baz {
  11.     public:
  12.     void bar(){
  13.         printf("Baz::bar\n");
  14.     }
  15. };
  16.  
  17. class BadClass {
  18.     public:
  19.     void bar(int i){
  20.         printf("BadClass::bar(%d)\n", i);
  21.     }
  22. };
  23.  
  24. template <class T>
  25. void fun(T arg) {
  26.     arg.bar();
  27. }
  28.  
  29. int main() {
  30.     Foo f;
  31.     Baz b;
  32.     fun(f);
  33.     fun(b);
  34.     BadClass bc;
  35.     fun(bc); //error on compile time
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment