Why should pop() take an argument?

前端 未结 5 809
你的背包
你的背包 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:55

    IMO, a good signature for the eqivalent of Java's pop function in C++ would be something like:

    boost::optional pop();
    

    Using option types is the best way to return something that may or may not be available.

提交回复
热议问题