godfat (owner)

Revisions

gist: 78509 Download_button fork
public
Public Clone URL: git://gist.github.com/78509.git
Embed All Files: show embed
none.cpp #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#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
*/