Why should pop() take an argument?

前端 未结 3 1870
不思量自难忘°
不思量自难忘° 2021-02-15 02:25

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

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 02:48

    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.

提交回复
热议问题