Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // test.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <memory>
- #include <iostream>
- struct Foo {
- Foo(int o) {
- one = o;
- }
- int one;
- virtual int getOne() { return one; }
- };
- struct Bar : public Foo {
- Bar(int o, int t) : Foo(o) {
- two = t;
- }
- int two;
- virtual int getOne() override { return one * two; };
- int getTwo() { return two; }
- };
- int main()
- {
- using namespace std;
- shared_ptr<Foo> bar = make_shared<Bar>(1, 2);
- cout << "one " << bar->getOne() << endl;
- cout << "two " << dynamic_cast<Bar*>(bar.get())->getTwo() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement