简体   繁体   中英

What does ->std::ostream& mean?

Here is the part of codes that i cannot understand.This is a func definition.

using sPtr = std::shared_ptr < std::vector<int> >;
auto print(sPtr vec) ->std::ostream&;

what does it mean by -> std::ostream& ? Is it necessary or not ? In my opinion,

void print (sPtr vec) ;

I am learning CPP5 ch12 now, and the code is from github Mooophy/Cpp-Primer; Thanks everyone's advice.

print is a function taking a sPtr as an input and returning an std::ostream& . The syntax being used was introduced in C++11, and it's called "trailing return type" .

The declaration of print can be rewritten as follows:

std::ostream& print(sPtr vec);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM