Find out the bug in this code,because of that this code
will not compile.......

#include <iostream>
#include <new>
#include <cstring>
using namespace std;

class balance {
double cur_bal;
char name[80];
public:
balance(double n, char *s) {
cur_bal = n;
strcpy(name, s);
}
~balance() {
cout << "Destructing ";
cout << name << "\n";
}
void set(double n, char *s) {
cur_bal = n;
strcpy(name, s);
}
void get_bal(double &n, char *s) {
n = cur_bal;
strcpy(s, name);
}
};

int main()
{
balance *p;
char s[80];
double n;
int i;

try {
p = new balance [3]; // allocate entire array
} catch (bad_alloc xa) {
cout << "Allocation Failure\n";
return 1;
}

Answers were Sorted based on User's Feedback



Find out the bug in this code,because of that this code will not compile....... #include <io..

Answer / pramodsingh_45

this is the key point in c++ when you are allocating entire
array by new operator....you must add parameterless
constructor...

so here is the solution....
add this...within the class.

balance() {}//parameterless constructor

and be happy..... :)

Is This Answer Correct ?    5 Yes 0 No

Find out the bug in this code,because of that this code will not compile....... #include <io..

Answer / santhoo035

Default constructor is not overriden

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More C++ General Interview Questions

What is struct c++?

1 Answers  


what is importance of data sturture in a programming language?

22 Answers   L&T, TCS, Wipro,


Explain function overloading

1 Answers  


How the V-Table mechanism works?

6 Answers   HP,


Generally variables are stored in heap memory. When he variables are created in stack?

4 Answers   Persistent,


What is c++ 11 and c++ 14?

1 Answers  


What is polymorphism and its type in c++?

1 Answers  


What are C++ inline functions?

1 Answers  


write infinite loop in C++ which does not use any variable or constant?

3 Answers  


Is java as fast as c++?

1 Answers  


You run a shell on unix system. How would you tell which shell are you running?

1 Answers  


What is meant by forward referencing and when should it be used?

1 Answers  


Categories