C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - General Questions (Q.No. 8)
8.
Which of the following statement is incorrect?
Discussion:
34 comments Page 2 of 4.
Ashutosh Londhe said:
1 decade ago
Compiler always provide parameter-less constructor, so option B is correct. But we can declare constructor as private so that we can create object of class outside member function for ex:constructor and copy constructor in singleton class is private.
Amit Singh Gaurav said:
1 decade ago
Constructor may be private. According to your need, in some scenario where you need to create objects depends on your need then you have to declare the constructor as private. (for ex in Singleton design pattern we use constructor as private).
Ravi said:
1 decade ago
For option C, if a constructor is private, then what is the use of that if we can't create an object of that class.
If we try to create object of a class whose constructor is private, it will give error :: constructor () is private.
If we try to create object of a class whose constructor is private, it will give error :: constructor () is private.
Navin said:
1 decade ago
Compiler by default provide public constructor. Constructor can be private. To implement singleton class we have to make constructor private. (Google for how to make singleton class).
Zbik said:
9 years ago
It seems to that the answer B is incorrect. Let us assume that we define a constructor with parameters. In such situation a compiler would not generates the default constructor!
Krish said:
1 decade ago
What about the second option?Compiler by default provides a zero argument constructor only right?Can any one comment if compiler provides a parameterized constructor too.
Utsav said:
1 decade ago
How can constructor can't be private? If we consider design patterns, for singleton pattern implementation, constructor should be private.
Prem said:
1 decade ago
Compiler does not always provide zero value constructor. It does provide one such constructor when no other constructors are defined.
Abirami said:
1 decade ago
The option B will be correct as the compiler will not provide default constructor when user defined any constructor.
Alex said:
1 decade ago
Have you heard of Singleton pattern? The constructor is private and the object is created via a static function.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers