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

Can you call a constructor within a constructor?

Answer Posted / jinendra pandey

when i am tring above code getting following error
Can we call a constructor within a constructor?

Error:------------>
object.cpp: In constructor Account::Account():
object.cpp:15: error: this cannot be used as a function


#include<iostream.h>
class Account {
private:
double balance;

// 1st Constructor
public:
Account( double initBalance ) {
balance = initBalance;
}

// 2nd Constructor
public:
Account() {
this( 0.0 ); // call the 1st constructor
}
};

int main()
{
Account a;
return 0;
}

Error:------------>
object.cpp: In constructor Account::Account():
object.cpp:15: error: this cannot be used as a function

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

List some important characteristics on jre

1064


What is map in java?

996


What are the different access modifiers available in java?

1033


What is identifier in java?

1103


How do you reverse a word in java?

1069


Does java have extension methods?

970


Can a class with private constructor be extended?

938


What is the use of volatile in java?

1050


Is a case study a method or methodology?

893


How to perform quicksort in java?

1103


Can we overload destructor in java?

983


Why main() method is public, static and void in java ?

1088


What are the advantages of encapsulation in java?

1004


How will you call an Applet using Java Script Function?

1025


Is java programming easy?

986