Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does scope resolution operator do?

1049


Explain the properties and principles of oop.

959


Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.

1001


Explain linked list using c++ with an example?

1021


Explain the purpose of the keyword volatile.

1102


What is an operator function? Describe the function of an operator function?

1065


Define the operators that can be used with a pointer.

993


How would you use qsort() function to sort an array of structures?

1063


Explain about Virtual Function in C++?

972


Write a program to find the reverse Fibonacci series starting from N.

1164


What is difference between rand () and srand ()?

1037


What is a tuple c++?

960


Is ca high or low level language?

1013


What is the difference between structure and class?

1158


Write is a binary search tree? Write an algo and tell complexity?

969