Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:09:20+00:00 2026-06-13T18:09:20+00:00

Possible Duplicate: What is -> after function declaration? I’ve just come across the following

  • 0

Possible Duplicate:
What is “->” after function declaration?

I’ve just come across the following examples of C++ functions using the new auto keyword, and I was hoping someone could help me understand what the syntax means.

template <class T, class U>
auto add(T t, U u) -> decltype(t + u);

auto f = [](int a, int b) -> int {
   return a*b;
};

Specifically, I’m confused about the user of -> in the function signature and I would expect these to be written in the as

template <class T, class U>
auto add(T t, U u)
{
    decltype(t + u);
}

auto f = [](int a, int b){
    return a*b;
};

What’s the -> operator doing in there, and where can I learn more about this syntax?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:09:22+00:00Added an answer on June 13, 2026 at 6:09 pm

    What’s the -> operator doing in there?

    That’s a trailing return type. Instead of:

    int f();
    

    you can equivalently write:

    auto f() -> int;
    

    If the return type depends on the function parameter types, then you need to use this form; the parameters aren’t available until after they’ve been declared:

    decltype(t+u) add(T t, U u); // Error: uses `t` and `u` before they're declared
    auto add(T t, U u) -> decltype(t + u); // OK
    

    Also, if you want to specify the return type of a lambda, then you must use this form; although, as you point out, in many cases (including this one) you don’t need to specify that at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: jQuery: Return data after ajax call success I have the following function
Possible Duplicate: C++ Using stringstream after << as parameter I've a function like this
Possible Duplicate: What is useful about this C syntax? C variable declarations after function
Possible Duplicate: Determine original name of variable after its passed to a function. I
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
Possible Duplicate: What does const mean following a function/method signature? Go ahead laugh at
Possible Duplicate: Putting E-mail into sent folder after PHP mail function I've tried sending
Possible Duplicate: Python nested functions variable scoping After much trial and error I have
Possible Duplicate: What do parentheses surrounding a JavaScript object/function/class declaration mean? What does this
Possible Duplicate: Do the parentheses after the type name make a difference with new?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.