Quick actions

cmd+k|ctrl+k

Navigation

Languages

Whoami fixed

Snippet info

Language

Cpp

Visibility

public

Author

johan.van.breda

Created

2019-07-31T10:51:38Z

Updated

2019-07-31T10:51:38Z

#include <iostream>
#include <vector>
#include <algorithm>

class A 
{
public:
    A() {}
    virtual void whoami() const { std::cout<<"I am an instance of A"<<std::endl; }
    virtual ~A() {}
};

class B : public A
{
public:
    B() : A() {}
    void whoami() const override { std::cout<<"I am an instance of B"<<std::endl; }
    ~B() {}
};

void consume( const A& a )
{
  a.whoami();
}

int main() {
    std::vector<B> a(10,B());
    std::for_each( begin(a),end(a), [](const A& a) {consume(a); } );
    return 0;
}
INFO