Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Script started on Sun Jan 24 16:25:21 2016
- $ cat test.cpp
- #include <iostream>
- class Foo {
- public:
- int x;
- virtual void print();
- };
- class Bar: public Foo {
- public:
- int y;
- virtual void print();
- };
- void Foo::print() {
- std::cout << "x: " << this->x << '\n';
- }
- void Bar::print() {
- std::cout << "x: " << this->x << " y: " << this->y << '\n';
- }
- void print(Foo foo) {
- foo.print();
- }
- void print2(Foo &foo) {
- foo.print();
- }
- void print3(Foo *foo) {
- foo->print();
- }
- int main() {
- Bar bar;
- bar.x = 5;
- bar.y = 10;
- print(bar);
- print2(bar);
- print3(&bar);
- }
- $ g++ test.cpp
- $ ./a.out
- x: 5
- x: 5 y: 10
- x: 5 y: 10
- Script done on Sun Jan 24 16:25:31 2016
Advertisement
Add Comment
Please, Sign In to add comment