answersLogoWhite

0

No.

If you do not provide a default constructor, the compiler will provide a default constructor that simply allocates memory for the class, but it will not initialize the members of the class.

If you do not provide a copy constructor, then the compiler will provide a copy constructor that allocates memory for the class, and then copies the member's data from class to class. This is bad if the class contains pointers, because only the pointer will be copied - the objects to which the pointers point will not be copied - and you could wind up deleting an object and then using it after deletion, with potentially devastating consequences.

So, yes, it is mandatory, from a good practices point of view, and just plain mandatory when the class has pointers, to always provide a default constructor and a copy constructor, along with the appropriate destructor.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

How do you calculate the size of a class in memory in C plus plus?

Use sizeof( ).


Can you use c in c plus plus without using class and object?

Sure.


What is an instance class in C plus plus?

You have a class(i.g. MyClass): class MyClass{ public: int MyData; }; And then you use the class like this: int main(){ MyClass MyObject; MyObject.MyData=7; }


How do you use mandatory in a sentence?

Education is mandatory in many countries.It is mandatory that you attend this meeting.


How do you use the word mandatory in a sentence?

Education is mandatory in many countries.It is mandatory that you attend this meeting.


How do you use Mandatory sentences in a sentence?

Education is mandatory in many countries.It is mandatory that you attend this meeting.


Explain instantiation of objects in c plus plus?

Instantiation of a class literally means creating an instance of a class. This is the process of allocating memory for an object that you can use in your program.


What is the use of private constructor in c plus plus?

Private construction prevents objects from the class from being instantiated other than via a static member function of the class, a friend function or a friend class.


Why you prefer to having parent class in java?

Having a parent class in Java is not mandatory. It is a good approach to extend from a parent class that has much of the functionality that the current class needs already coded. This helps us re-use functionality/code and avoid redundant/duplicate code.


Represent a stack in c plus plus?

Use a vector with a base class type. Any objects derived from the base class can be pushed and popped from the vector just as you would from a stack.


What is a constructor and its mandatory to use constructor in a class?

A constructor is a method that is invoked when an object is created. As to being mandatory, that really depends on the programming language; in the case of Java, each class must have a constructor, however, in many cases Java will automatically provide a default constructor, so you don't really need to program it.


Why you use public mode in c plus plus?

To expose an interface to the class members. Without an interface of some kind, an object would be useless.