You should always define the copy constructor and assignment operator unless you specifically want to disable copy or explicity want to use the defaults. Coplien calls the the cannonical form (along with an appropriate constructor and destructor).
You should declare the copy constructor and assignment operator private and leave them unimplemented if
you want to disable copyability and assignability. Otherwise you should declare and implement the copy
constructor and assignment operator (and also the destructor by the rule of three) only if the compiler-provided
member-wise copy versions are not sufficient.
No, any problems.
The constructor is not needed at all as well as the destructor while C++ inheritence feature is
not the case.
In this one the construct
base_to_derive:[access specifiers][virtuallity qualifires][...],[...[derived_type_name]]
{
derived_constructor_instance (parameters,...) : base_to_derive_constructor_from
(parameters,...)
{...;}
};
will never be got ridden of in its following classes.
Thanks for all the replies. My problem is here in the example below:
If in _YourClass, I include its constructor, it gives compilation error like this:
initlistref.cpp: In constructor ‘_YourClass::_YourClass()’:
initlistref.cpp:16: error: uninitialized reference member ‘_YourClass::myclass’
I am using initialization list and passing vector by reference.
Does anybody have any idea why this error is coming?
///////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
using namespace std;
class _MyClass
{
public:
_MyClass(){};
int variable;
};
typedef class _MyClass MyClass;
I want to change MyClass properties through YourClass. Hence I am passing MyClass by reference to YourClass constructor, taking its reference in private reference variable myclass and using it in other members of YourClass. If I want to use MyClass in other member functions of YourClass, I will have to take it in a local private variable and whatever changes I do with MyClass will change myclass variable in my main() function.
Please note there is no other path to achieve it so that a private class member
could be accessed in public ones class changefully. Also such classes are uninheritable
by a constrictive reason of a cross reference despite of all the C++ flexibility.
Of course the advanced typecast will provide more aids down over a journey up to the
higher level storage steps.