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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:55:05+00:00 2026-06-13T23:55:05+00:00

i was doing some tests of the move semantics and I tried this :

  • 0

i was doing some tests of the move semantics and I tried this :

class A{
public:
    A(){printf("A CTOR\n");}
    A(A&) {printf("A CTOR by copy\n");}
    A(A&&){printf("A CTOR by universal reverence\n");}
};

A&& create(){
    A v;
    return std::move(v);
}

auto x{ create() };//this does not compile

float d[]{1.2,1.3,5,6};//this does compile

I get the following error:

error C3086: cannot find 'std::initializer_list': you need to #include <initializer_list>

I don’t understand as the initializer list feature has been added to VC11 with CTP2012 nov.
Is this because we have to wait for an update of the stdlib ?

I think the code is correct as I copied it from a slide from Scott meyers: Move Semantics, Rvalue References, Perfect Forwarding.

Thank you for your help.
For your information, the spurious copies occured because i did not add “const” in my CTOR by copy.
Best

  • 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-13T23:55:06+00:00Added an answer on June 13, 2026 at 11:55 pm

    Braces with auto will always end up in std::initializer_list<T> type. So basically what happens here you try to create a std::initializer_list<A> here for x instead of A what probably was your intent here. However your code should compile fine and that may be a bug in the VS latest CTP compiler.

    To make x be of A you have 2 options:

    1. Do not use auto here:

      A x{ create() };
      
    2. Do not use Uniform initialization here:

      auto x(create());
      

    Beside that I see 2 other issues in you code. Firstly signature of proper copy-constructor should look like that:

    A(const A &) {printf("A CTOR by copy\n");}
    

    Moreover it is not encouraged to return RValue references from functions. Instead you should return by value like that:

    A create(){
      A v;
      return v;   // std::move not needed here because C++11 compiler will put it for you here
    }
    

    or just:

    A create(){
      return A();
    }
    

    EDIT:

    Oh and just to be politically correct A(A&&) is not “A CTOR by universal reference”. It is “A CTOR by move” or “A CTOR by rvalue reference” depending on which level of abstraction you want to operate. Universal reference is always about templates and that specific type type deduction.

    Please also read an article of Scott Meyers I attached in a different comment http://scottmeyers.blogspot.com/2012/10/copying-constructors-in-c11.html where the same C++ guru that you refer in your notes exactly explains the problems you face. Hope that helps.

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

Sidebar

Related Questions

I'm doing some tests with new features of CSS3, but this combination only works
I am doing some tests, just to learn (normally i do this in ajax
I'm doing some tests, but I see no difference when I use or not
I'm basically just doing some tests to figure out a good way to write
I was previously working with Ember.StateManager and now I'm doing some tests before I
I'm new in Silverlight and i am doing some tests. With my current test
I'm developing an application with Spring 3. I'm doing some tests with spring batch.
I'm doing some unit tests for an EntityEventListener from NHibernate, and I'm got stuck
While doing some JavaScript performance tests I came up with the following piece of
I execute some tests within my application, but before doing that I have to

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.