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"

LmTinyToon
  • 4,205
  • 3
  • 22
  • 46
  • 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 – LmTinyToon Jul 07 '16 at 16:12

0 Answers0