Consider this:
#include <iostream> struct A{ A(){ std::cout << "Create empty A" << std::endl; } A(const A& a){ // Why is this never called?? std::cout << "Never called" << std::endl; } }; A genA() { A a; return a; } int main(int argc, const char *argv[]) { A a(genA()); // Expected to call copy constructor return 0; } Why is the copy constructor not called?
What should I do if I want to ensure that "Never called" is printed on the screen every time I copy A.
-fno-elide-constructorsto disable the copy elision.