POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: My first C++ program Server Time
4 Nov 2024 17:36:50 EST (-0500)
  Re: My first C++ program  
From: Nicolas Alvarez
Date: 19 Sep 2008 19:33:45
Message: <48d436d8@news.povray.org>
Invisible wrote:
> I wrote a function that returns the top element from the stack while
> simultaneously removing it. That cuts down the typing quite a bit.

The reason that isn't built-in is that it doesn't work well with objects.

If vector.pop_back() returned a reference to the popped object, you'd get
sure crashes (reading from freed memory, or at least, a destructed object).

If vector.pop_back() returned a copy of the popped object, you'd get bad
performance even when you don't need the object (useless copying), you just
want to remove it. And who would free that copy?

ints, however, are easily copyable and don't need "freeing" :)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.