[ create a new paste ] login | about

Link: http://codepad.org/tMVtOiyZ    [ raw code | output | fork ]

C++, pasted on Sep 23:
#include<iostream>

struct OtherLibObject {
  void* userPointer;
};
template<class T>
class Base {
  typedef T type;
};

class Cat :Base<Cat>{
public:
  void say() {
    std::cout << "nyaaaa\n";
  }
};

class Dog {
  void say() {
    std::cout << "wan\n";
  }
};


int main() {
  Cat *p = new Cat();
  OtherLibObject obj;
  obj.userPointer=p;
  (Base::type)obj.userPointer->say();
//  ((Cat*)(obj.userPointer))->say();
  return 0;
}


Output:
1
2
3
In function 'int main()':
Line 29: error: 'template<class T> class Base' used without template parameters
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: