fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <unordered_map>
  4. #include <vector>
  5. using namespace std;
  6. class A{
  7. public:
  8. virtual void sing()=0;
  9. protected:
  10. virtual ~A(){std::cout<<"~A\n";};
  11. };
  12. class B : public A{
  13. public:
  14. virtual void sing(){std::cout<<"do re mi\n";};
  15.  
  16. virtual ~B(){std::cout<<"~B\n";};
  17. };
  18.  
  19. shared_ptr<A> creatA(){
  20. //shared_ptr<A> P=make_shared<B>();
  21. //shared_ptr<A> P(new B());
  22. shared_ptr<A> P(new B());
  23. return P;
  24. }
  25.  
  26.  
  27.  
  28. int main() {
  29. typedef std::vector<shared_ptr<A>> container_type;
  30. typedef std::vector<shared_ptr<A>>::iterator itee;
  31. container_type cont;
  32. for(int i=0;i<3;i++){
  33. cont.push_back(creatA());
  34. }
  35. for(itee ite=cont.begin();ite!=cont.end();++ite){
  36. (*ite)->sing();
  37. }
  38.  
  39. // your code goes here
  40. //shared_ptr<std::unordered_map<std::string, std::string>> ptrMapTemp = make_shared<std::unordered_map<std::string, std::string>>();
  41.  
  42. shared_ptr<std::unordered_map<std::string, std::string>> ptrMapTemp;
  43. /*if(ptrMapTemp->empty()){
  44. cout<<"aaa"<<endl;
  45. }*/
  46.  
  47.  
  48. std::cout<<"main\n";
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5544KB
stdin
Standard input is empty
stdout
do re mi
do re mi
do re mi
main
~B
~A
~B
~A
~B
~A