admin管理员组文章数量:1124552
By experiment, it seems CStringT::MakeReverse
and CStringT::MakeUpper
all change the string in-place.
What is the keyword on CStringT
Class documentation, which I should pay attention to, saying these operations are "in-place"?
Returning a value implies the methods create new copies in my newbie's opinion.
By experiment, it seems CStringT::MakeReverse
and CStringT::MakeUpper
all change the string in-place.
What is the keyword on CStringT
Class documentation, which I should pay attention to, saying these operations are "in-place"?
Returning a value implies the methods create new copies in my newbie's opinion.
Share Improve this question edited 2 days ago wohlstad 27.2k16 gold badges54 silver badges85 bronze badges asked 2 days ago Jason ChoJason Cho 331 silver badge6 bronze badges 11 | Show 6 more comments1 Answer
Reset to default 4Collecting the good points mentioned in the comments above:
There are several points in the CStringT
documentation that give hints that the methods are mutating the current object in place:
The main hint is that the methods return a reference -
CStringT&
.
If they were creating a new object it would have been returned by value.
There is no other object which it make sense to return a refernce to here, execpt for the current one.Additional points that supports this:
The methods are not marked as
const
. Although it is not a must, methods that do not modify the object should be marked asconst
, and the lacking of it hints that these methods do modify it.The name of the methods starting with
Make
usually hint that they modify the current object to "make" it something else.The documentation text, e.g. "Reverses the order of the characters in the CStringT object." hints that the current object will be modified.
版权声明:本文标题:c++ - How to tell if a class method changes the object in-place (in Microsoft's documentation)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736635038a1945858.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
MakeSomething
is a typical clue that it will be modify because you are making it into a specific condition. – NathanOliver Commented 2 days agoCStringT&)
, so I guess you can assume that means it returns itself. – 001 Commented 2 days agoCStringT
is a Microsoft thing, not standard C++. The question is about how to read Microsoft's documentation, often a difficult proposition. – Pete Becker Commented 2 days ago