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;
}

Answer Posted / santhoo035

Default constructor is not overriden

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the classes in c++?

652


Explain the difference between overloading and overriding?

627


What is object file? How can you access object file?

607


Which is best ide for c++?

577


What is the latest c++ standard?

697






Explain the auto storage classes in c++.

612


Is there a sort function in c++?

558


which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?

732


What is c++ and its uses?

635


When does a name clash occur in c++?

723


Why is c++ called oops?

571


What is enum c++?

627


Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).

628


What is #include math h in c++?

581


Differentiate between a constructor and a destructor in c++.

577