天宮鏡花 天宮鏡花 - 13 days ago 4
C++ Question

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.

Answer

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);
Comments