Re: 'auto' and const references

Discussion in 'C++' started by SG, May 3, 2013.

  1. SG

    SG Guest

    Am 03.05.2013 15:16, schrieb Juha Nieminen:
    > Let's say that a function returns a const reference. If I say this:
    >
    > auto x = thatFunction();
    >
    > what would the type of 'x' be? Will it be a const reference, thus
    > eliding copying, or will a copy be made?


    No, it's not. It's like template argument deduction for a parameter "T
    x" where you pass in thatFunction(); as argument. So, x won't be a
    reference.

    > Is there any difference to these:
    >
    > auto& x = thatFunction();
    > const auto& x = thatFunction();


    Sure. But I think you can figure it out now.

    HTH,
    SG
    SG, May 3, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Javier
    Replies:
    2
    Views:
    533
    James Kanze
    Sep 4, 2007
  2. linkswanted
    Replies:
    1
    Views:
    862
  3. Victor Bazarov

    Re: 'auto' and const references

    Victor Bazarov, May 3, 2013, in forum: C++
    Replies:
    5
    Views:
    198
  4. Balog Pal

    Re: 'auto' and const references

    Balog Pal, May 4, 2013, in forum: C++
    Replies:
    2
    Views:
    243
    Balog Pal
    May 5, 2013
  5. K. Frank
    Replies:
    4
    Views:
    170
Loading...

Share This Page