[ create a new paste ] login | about

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

pyrtsa_ - C++, pasted on Jul 7:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <boost/shared_ptr.hpp>

struct base {
    int i;
    explicit base(int i) : i(i) {}
    virtual ~base() {}
    virtual int id() const { return i; }
};

struct child : base {
    explicit child(int i) : base(i) {}
    virtual int id() const /*override*/ { return i + 1000; }
};

int main() {
    boost::shared_ptr<base> p(new child(13));
    std::cout << p->id()       << std::endl; //=> 1013
    std::cout << p->base::id() << std::endl; //=> 13
}


Output:
1
2
1013
13


Create a new paste based on this one


Comments: