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 1 of 2.
Jenny said:
6 years ago
First of all, it should be <iostream>
And next would be ~Bix(); as ~Bix(){};
And next would be ~Bix(); as ~Bix(){};
Raghavendra said:
6 years ago
It's because of cout it should be std::cout and include file should be iostream not iostream.h.
Priya modak said:
7 years ago
It is because of undefined reference to the destructor.
write ~Bix(); as ~Bix(){};
Then it will work.
write ~Bix(); as ~Bix(){};
Then it will work.
Neha said:
7 years ago
program throw runtime error =Bix::~Bix(void)" not compile time.
Please help me to solve this.
Please help me to solve this.
Niketa Agarwal said:
9 years ago
It is because of undefined reference to destructor.
write ~Bix(); as ~Bix(){};
Then it will work.
write ~Bix(); as ~Bix(){};
Then it will work.
(1)
Vigneshwar said:
9 years ago
Const function does not allow the object members to be modified. In this program, we are not modifying so it will print the output 25.
Jayanthi Akula said:
10 years ago
When we are calling any constant function. The object of that function should be constant. Here in program "objB" is the object of "Bix" which is having a normal object.
So a normal object can not call its constant function. Try the program by declaring the object as "const" like const Bix objB.
So a normal object can not call its constant function. Try the program by declaring the object as "const" like const Bix objB.
Guriya said:
1 decade ago
Yes, runtime error: undefined symbol Bix::~Bix().
Sid said:
1 decade ago
Yes its run time error. So answer is D.
Swetha said:
1 decade ago
The program get compiled and it provides only run time error.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers