#include <iostream>
#include <list>
#include <memory>
using namespace std;

struct A {
	virtual void showb() {cout<<"showa"<<endl;} // if no virtual, dynamic_cast will not compile
};
struct B : A {
	void showb() {cout<<"showb"<<endl;}
};

int main() {
	
	list <shared_ptr<A>> container; 
	shared_ptr<B> b = shared_ptr<B>(new B);
	container.push_back(b);
	
	auto it = container.begin();
   	shared_ptr<B> aB = static_pointer_cast<B>(*it);
	aB->showb(); 

	container.push_back(make_shared<A>());
	for (auto i = container.begin(); i!=container.end(); i++) {
		shared_ptr<B> spb = dynamic_pointer_cast<B>(*i); 
		if (spb)
			spb->showb();  // at least one virtual function 
		else cout << "the pointer was not to a B"; 
	}
		
	// your code goes here
	return 0;
}