0

I am using msvc 2013. I have following code:

#include <iostream>

struct A
{
   A(void)
   {
      std::cout << "A()" << std::endl;
   }
   A(const A& a)
   {
      std::cout << "A(const A&)" << std::endl;
   }
   A(A&& a)
   {
      std::cout << "A(A&&)" << std::endl;
   }
   static void foo(const A& a)
   {
      std::cout << "Foo" << std::endl;
   }
};

int main(void)
{
  A::foo(A(A()));
  int i = 0;
  std::cin >> i;
}

When I run program, copy and move constructors of struct A are ignored. I really don't understand this case. Output is: "A() Foo"

Alex Aparin
  • 4,393
  • 5
  • 25
  • 51
  • Few hours before I just asked the same question here http://stackoverflow.com/questions/38246823/why-is-the-move-constructor-not-called – Gilson PJ Jul 07 '16 at 16:08
  • Thanks, I have understood my problem. This problem is called copy elision. http://en.cppreference.com/w/cpp/language/copy_elision – Alex Aparin Jul 07 '16 at 16:12

0 Answers0