Why should an API return 'void'?

前端 未结 7 1427
南方客
南方客 2021-02-07 00:23

When writing an API or reusable object, is there any technical reason why all method calls that return \'void\' shouldn\'t just return \'this\' (*this in C++)?

For examp

7条回答
  •  广开言路
    2021-02-07 00:48

    Is there a technical reason for following this route?

    One of the C++ design guidelines is "don't pay for features you don't use"; returning this would have some (slight) performance penalty, for a feature which many people (I, for one) wouldn't be inclined to make use of.

提交回复
热议问题