c++ - [Prob]Why copy constructor is not getting called -
i have created class , initialized array of objects through constructor, why or why not copy constructor getting called here? copy elision?
#include<iostream> #include<stdio.h> class abc { int x, y; public: abc() { x = 0; y = 0; } abc(int a,int b) { x = a; y = b; } abc(const abc &obj) { std::cout<<"copy called"; } }; int main() { abc obj[2] = {abc(), abc(5,6)}; //copy elision or copy constructor? }
you're right, it's copy elision, compiler optimisations , creates objects right in place of memory allocated within array, hence copy constructor doesn't called.
Comments
Post a Comment