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 8635329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:56:53+00:00 2026-06-12T09:56:53+00:00

The new C++11 standard adds a new function declaration syntax with a trailing return

  • 0

The new C++11 standard adds a new function declaration syntax with a trailing return type:

// Usual declaration
int foo();

// New declaration
auto foo() -> int;

This syntax has the advantage of letting the return type be deduced, as in:

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

But then why the return type was put before the function name in the first place? I imagine that one answer will be that there was no need for such type deduction in that time. If so, is there a reason for a hypothetical new programming language to not use trailing return type by default?

  • 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-12T09:56:55+00:00Added an answer on June 12, 2026 at 9:56 am

    As always, K&R are the “bad guys” here. They devised that function syntax for C, and C++ basically inherited it as-is.

    Wild guessing here:
    In C, the declaration should hint at the usage, i.e., how to get the value out of something. This is reflected in:

    • simple values: int i;, int is accessed by writing i
    • pointers: int *p;, int is accessed by writing *p
    • arrays: int a[n];, int is accessed by writing a[n]
    • functions: int f();, int is accessed by writing f()

    So, the whole choice depended on the “simple values” case. And as @JerryCoffin already noted, the reason we got type name instead of name : type is probably buried in the ancient history of programming languages. I guess K&R took type name as it’s easier to put the emphasis on usage and still have pointers etc. be types.

    If they had chosen name : type, they would’ve either disjoined usage from declarations: p : int* or would’ve made pointers not be types anymore and instead be something like a decoration to the name: *p : int.

    On a personal note: Imagine if they had chosen the latter and C++ inherited that – it simply wouldn’t have worked, since C++ puts the emphasis on types instead of usage. This is also the reason why int* p is said to be the “C++ way” and int *p to be the “C way”.

    If so, is there a reason for a hypothetical new programming language to not use trailing return type by default?

    Is there a reason to not use deduction by default? 😉 See, e.g. Python or Haskell (or any functional language for that matter, IIRC) – no return types explicitly specified. There’s also a movement to add this feature to C++, so sometime in the future you might see just auto f(auto x){ return x + 42; } or even []f(x){ return x + 42; }.

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

Sidebar

Related Questions

I want to make a function for a new datatype in Standard ML, the
Consider this is a standard Linq from q in SomeQuery select new SomeObject {
the database we work on has some standard permissions for new users, but from
I'm attempting to use the new standard way of loading seed data in Rails
I'm new to Standard ML and I'm trying to get my head around the
I'm fairly new to C++ standard library and have been using standard library lists
I'm still pretty new to ObjC. I noticed that it's pretty standard everywhere to
I mean the standard (?) random generator in .net /c# Random random = new
I've encountered a customers sandbox where the standard Save and Save & New buttons
From what I understand, in standard C++ whenever you use the new operator you

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.