Why should pop() take an argument?

前端 未结 5 807
你的背包
你的背包 2021-02-15 02:09

Quick background
I\'m a Java developer who\'s been playing around with C++ in my free/bored time.

Preface
In C++, you often see

5条回答
  •  误落风尘
    2021-02-15 02:39

    Using C++0x makes the whole thing hard again.

    As

    stack.pop(item); // move top data to item without copying
    

    makes it possible to efficiently move the top element from the stack. Whereas

    item = stack.top(); // make a copy of the top element
    stack.pop(); // delete top element
    

    doesn't allow such optimizations.

提交回复
热议问题