Answers were Sorted based on User's Feedback
Answer / sampurna pandey
yes, we can have both private constructor and destructor
and can use them with help of static function for example
static int i;
static Base *Creat_Object();
static void Destroy_Object(Base *p);
cout<<i<<" Add function"<<endl;
Base * ptr = new Base();
void Base::Destroy_Object(Base *p)
Base *temp = Base::Creat_Object();
correct me if i am wrong.
|Is This Answer Correct ?||21 Yes||3 No|
Answer / guest
You can have private constructors. It's pretty common
practice when you create a class which you want to never be
constructed with "new" from outside the class (for example,
if you have a static factory member of the class).
|Is This Answer Correct ?||10 Yes||1 No|
Answer / vaibhav meena
We can have Private Destructor and by using Friend Function
we can also instantiate it. :)
|Is This Answer Correct ?||6 Yes||0 No|
Answer / subrat
Please visit this url for more clarity on "Private
|Is This Answer Correct ?||1 Yes||0 No|
Answer / binoy mathew
private: // note that constructor is private here
t *t1 = new t; // create a new obj
delete t1; // delete the obj, which calls destructor
Try to compile the above code.
following error results...
[root@localhost Desktop]# g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:13: error: ‘t::~t()’ is private
tt.cpp:: error: within this context
....implies, we can't have destructor private.
|Is This Answer Correct ?||1 Yes||3 No|
Answer / shakti singh khinchi
U can't instantiate instance of that class.
|Is This Answer Correct ?||0 Yes||3 No|
Answer / dhananjay
|Is This Answer Correct ?||2 Yes||5 No|
Answer / vishwa
we cannot say it destructors are not private. because for
empty class if we use delete operator then it is going to
delete the destructor which is private.
|Is This Answer Correct ?||0 Yes||8 No|
Answer / thuang
In replay to Vishwa,
for empty class, compiler will supply a default constructor
and a destructor for us, their access modifiers were public.
|Is This Answer Correct ?||0 Yes||8 No|
Answer / pooja
no we do not have private destructors because the
destructors can be declared only in public access
|Is This Answer Correct ?||1 Yes||11 No|
Explain dangling pointer.
A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a saleperson who sells $5000 worth of merchandise in a week receives $200 plus 9 percent of $5000, or a total of $650. You have been supplied with a list of items sold by each salesperson. The values of these items are as follows: Item Value A 239.99 B 129.75 C 99.95 D 350.89 Write a program that inputs one salesperson's items sold in a week (how many of item A? of item B? etc.) and calculates and displays that salesperson's earnings for that week.
What is problem with Runtime type identification?
How do you establish a has-a relationship?
What is the sequence of destruction of local objects?
A prime number is a number which is divisible only by itself and 1. Examples of the first few primes are 2, 3, 5, 7, 11. Consider writing a program which can generate prime numbers for you. Your program should read in and set a maximum prime to generate and a minimum number to start with when looking for primes. This program should be able to perform the following tasks: 1. Read the maximum number from user (keyboard input) to look for primes. The program should not return any primes greater than this number. 2. Read the minimum number from user (keyboard input) to look for primes. The program should not return any primes less than this number. 3. Generate and print out every prime number between the maximum prime and minimum number specified by the user.
Explain what happens when a pointer is deleted twice?
How can we check whether the contents of two structure variables are same or not?
What is auto used for in c++?
What are the differences between a struct in C and in C++?
What is expression parser in c++
List out function which we can call without using object