Skip to content

Instantly share code, notes, and snippets.

@godfat
Created March 13, 2009 09:47
Show Gist options
  • Save godfat/78509 to your computer and use it in GitHub Desktop.
Save godfat/78509 to your computer and use it in GitHub Desktop.
#include <iostream>
template <class T>
class None: public T{
public:
static None<T>* none(){
static None<T> _;
return &_;
}
private:
None<T>(){}
};
class Base{
public:
virtual Base* test(){
static Base _;
return &_;
}
};
class Derived: public Base{
public:
virtual None<Base>* test(){
return None<Base>::none();
}
};
int main(){
using std::cout;
using std::endl;
Base base;
Derived derived;
Base* b;
b = base.test();
cout << "base: " << b << endl;
b = derived.test();
cout << "derived: " << b << endl;
cout << "none: " << None<Base>::none() << endl;
}
/*
base: 0x2048
derived: 0x204c
none: 0x204c
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment