#include<iostream> using namespace std; class x{ int p; public: x(){cout<<"constructor\n";} x(const x &y) { cout<<"copy constructor\n"; } ~x() { cout<<" destructor\n"; } void print() { cout<<"print statement\n"; } }; x g() { x b; b.print(); return b; } int main() { x b; x t=g(); }
#include<iostream> using namespace std; class x{ int p; public: x(){cout<<"constructor\n";} x(const x &y) { cout<<"copy constructor\n"; } ~x() { cout<<" destructor\n"; } void print() { cout<<"print statement\n"; } }; x g(x b) { b.print(); return b; } int main() { x b; x t=g(b); } why first one is not calling copy constructor in function g() while returning from it but second one is calling copy constructor in function g() while returning from it? in both program inside g() b is local but why giving different result. bruce ackel page number:467 please explain it. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.