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

what are different ways in which a thread can enter the waiting state? : Java thread

903


What is the difference between int and integer in java?

983


What is the difference between declaration and definition in java?

1000


What is JFC?

1159


What does provide mean construction?

1052


Can an anonymous class be declared as implementing an interface and extending a class in java programming?

1164


What is java thread dump, how can we get java thread dump of a program?

932


how its run?

1005


Can we use different return types for methods when overridden?

942


Can we override constructors?

939


Why spring singleton is not thread safe?

957


Why can't we make a class private in java?

976


How do you override a method in java?

951


What is multi level inheritance in java?

961


What is the difference between class & structure?

1120