c++ - How to prove that Copy Constructor is mandatory -
i have created class integer variable , pointer variable. after creating object , passed function. after returning function program not throwing exception
#include"iostream" using namespace std; class { public : int i; char *c; void show(); }; void func(a obj); int main() { a; a.i = 10; a.c = "string"; cout << " before fun " << endl; a.show(); cout << " going call func " << endl; func(a); cout << " after func " << endl; a.show(); return 0; } void a::show() { cout << " valuses in object " << << '\t' << c << endl; } void func(a aa) { cout << " valuses in object " << aa.i << '\t' << aa.c << endl; }
in func passing object (from main) , copied in aa (stack of func). after returning func if call show ( pointer c null of a), give me exception not happening . please me prove requirement of copy constructor
hide copy constructor. cause compilation error everywhere called implicitly.
class { public : int i; char *c; private: a(const a& _other); };
Comments
Post a Comment