3 ms·
Smart pointers are a weird example because they're ancient. I'd say the majority of C++ libraries expect C++11, many C++14. Also it's still completely normal t
by TillE 5y ago
Smart pointers are a weird example because they're ancient. I'd say the majority of C++ libraries expect C++11, many C++14.
Also it's still completely normal to use raw pointers or references when a function doesn't care about ownership.
- tialaramex 5y ago> Smart pointers are a weird example because they're ancient. I am an old man, and to me 2011 doesn't feel ancient, but fair. C++ 11 has unique_ptr and shared_ptr (if your library uses a previous generation of smart pointers you're in worse trouble than if it had raw pointers) and that's what you'd probably teach in class today. > Also it's still completely normal to use raw pointers or references when a function doesn't care about ownership. This is true. So you can't tell. And, with a different hat on it's also something that Kate Gregory has given talks about. As the new maintainer for several MLOC of C++ what can I conclude about this function that takes a raw pointer to a foo ? Maybe, it just wants to look at a foo, immediately and then has no further interest in it. Maybe, it will mutate the foo, immediately, and then loses interest. Maybe, it will hang on to this pointer and use it later, who knows when. Thus, now it "owns" the foo, I hope it will clean up after it ceases using it because I can't now. Maybe, I'm supposed to provide an "empty" foo and the contents of it afterwards are the primary result of the function. Those are pretty different, so it's disappointing that we don't learn which it is from the function signature.