To tylko jedna z 3 stron tej notatki. Zaloguj się aby zobaczyć ten dokument.
Zobacz
całą notatkę
Copy constructor in derived class It is a constructor so: - Remember the order of constructors: base class(es) constructor(s) will always run - One may supply parameters for base class constructor at initiation list - Remember: also member objects will be constructed class derived:public base { ... }; derived::derived(const derived & p) :base(p) // implicit conversion to base& { ... }; A copy constructor may be implicit (generated) as are default constructor and destructor Note: A constructor with no parameters is usually called a default constructor, whether it is implicitly declared or generated. - If it is not defined explicitly, it will be generated - Base class copy con. will be called before implicit copy constructor, (As opposed to the case of explicit copy con. where default base con. is called) - Base class copy con. must be available (exist and be public) Automatically generated (implicit) operator= will copy member-by-member - operator= from base class will be called before the operator= - operator= will not be implicit if the class contains const or reference fields (also inherited) in any parent class or member object operator= is private. - will not function well for pointer fields ( shallow copy) For explicit operator=, the inherited operator= will not be called automatically; one has to call it explicitly.
... zobacz całą notatkę
Komentarze użytkowników (0)