title: how to return a list of objects without destroying them
body: <p>How to fix the function 'func' so that it returns the objects without being destroyed?</p>
  <p>function 'func' must add the objects to a list and return them but be destroyed</p>
  <p>The Smoothy abstract class has a purely virtual description method (). DecoratorSmoothy
  contains a smoothy, description () and getPret () methods return the description and price
  aggregate smoothy.
  SmoothyCuFream and SmoothyCuUmbreluta classes add the text “cu crema”
  respectively “cu umbreluta” in the description of the smoothy contained. The price of a smoothy that has the cream increases by 2 euro, the one with the umbrella costs an extra 3 euro.
  BasicSmoothy class is a smoothy without cream and without umbrella, method
  description () returns the name of the smothy</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  class Smoothy {
  private:
      int pret=0;
  public:
      virtual string descriere() = 0;
      int getPret(){
          return pret;
      }
      void setPret(int a) {
          pret += a;
      }
  };
  class BasicSmooty : public Smoothy {
  private:
      string nume;
  public:
      BasicSmooty(string n) :
          nume { n } {}
      string descriere() {
          return nume;
      }
  };
  
  class DecoratorSmoothy : public Smoothy {
  private:
      Smoothy* smooty;
  public:
      DecoratorSmoothy() = default;
      DecoratorSmoothy(Smoothy* n) :
          smooty{ n } {}
      string descriere() {
          return smooty-&gt;descriere();
      }
      int getPret() {
          return  smooty-&gt;getPret();
      }
  };
  class SmootyCuFrisca : public DecoratorSmoothy {
  
  private:
      BasicSmooty bsc;
  public:
      SmootyCuFrisca(string desc) :
          bsc{ desc } {}
      string descriere() {
          setPret(2);
          return bsc.descriere() + &quot; cu frisca &quot;;
      }
  };
  
  class SmootyCuUmbreluta : public DecoratorSmoothy{
  
  private:
      BasicSmooty bsc;
  public:
      SmootyCuUmbreluta(string desc) :
          bsc{ desc } {}
      string descriere() {
          setPret(3);
          return bsc.descriere() + &quot; cu umbreluta &quot;;
      }
      ~SmootyCuUmbreluta() {
          cout &lt;&lt; &quot;rip&quot;;
      }
  };
  vector&lt;Smoothy*&gt; func(void)
  {
      std::vector&lt;Smoothy*&gt; l;
  
      SmootyCuFrisca a1{ &quot;smooty de kivi&quot; };
      SmootyCuUmbreluta a2{ &quot;smooty de kivi&quot; };
      SmootyCuFrisca a3{ &quot;smooty de capsuni&quot; };
      BasicSmooty a4{ &quot;smooty simplu de kivi&quot; };
  
      l.push_back(&amp;a1);
      l.push_back(&amp;a2);
      l.push_back(&amp;a3);
      l.push_back(&amp;a4);
      
      return l;
  }
  int main() {
      
      
      vector&lt;Smoothy*&gt; list;
          
     // Here when i call func() objects are distroyed
      list = func();
  
      return 0;
  }
  </code></pre>