Created
March 13, 2009 09:47
-
-
Save godfat/78509 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> | |
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