C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - Programs (Q.No. 3)
3.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class Bix
{
int x;
public:
Bix();
~Bix();
void Show() const;
};
Bix::Bix()
{
x = 25;
}
void Bix::Show() const
{
cout<< x;
}
int main()
{
Bix objB;
objB.Show();
return 0;
}
Discussion:
19 comments Page 2 of 2.
Vineet said:
1 decade ago
Destructor should be define.
Rexi said:
1 decade ago
Destructor has to destroy the object. Thus we have to define destructor inside the main function.
Bob marley said:
1 decade ago
In this program we should also define the destructor, like as,
~Bix()
{ }
It should be like that...we can't not left destructor without defining it :).
~Bix()
{ }
It should be like that...we can't not left destructor without defining it :).
Prabuferoz said:
1 decade ago
void show() should be declared before destructor.
Bittoo said:
1 decade ago
If destructor cannot be declared, it must be defined within class.
Jyoti said:
1 decade ago
The destructor is not provided the definition.
Priyank said:
1 decade ago
The destructor is only declared, but not defined anywhere
i.e, it is given like this "Bix::~Bix()" and left without definition.
i.e, it is given like this "Bix::~Bix()" and left without definition.
Sai said:
1 decade ago
Kindly note that it's not due to inaccessibility of x. it is very well accessible in Bix::<<anything>> . The destructor is only declared, but not defined anywhere. Hence the compiler throws " undefined reference to Bix::~Bix()" when it's called after the return statement of main().
Sindhu said:
1 decade ago
Here x is declared as private so we cannot access x in main function.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers