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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -