-1

This syntax is so strange, I don't know how to understand it.

I don’t know what it means, and I tried searching on major search engines, but the keywords were clueless and no results were found.

Please help me, thanks.

auto parser::error(const std::string& msg) -> void
{
    std::cerr << msg << std::endl;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
qianqian
  • 25
  • 4

1 Answers1

2

This is C++ 11, with auto type deduction syntax for function return type. The trailing part -> void is called as trailing return type syntax

I will refer you to Effective Modern C++ by Scott Meyers. This syntax is detailed in Item-3 "Understand decltype" of this book, so just reading the first-3 items will make this syntax clear to you.

This particular case does not seem to be a good use case for this syntax, and it can simply be written as below

void parser::error(const std::string& msg)
{
    std::cerr << msg << std::endl;
}