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 do you know about the garbage collector in java?

558


What do you mean Abstraction in java?

593


What is bubble sorting in java?

579


What is Hierarchy of exception?

630


Explain illegalmonitorstateexception and when it will be thrown?

598






What is the purpose of garbage collection in java? When is it used?

526


How does callback work in java?

591


Explain about version control?

575


What will be the initial value of an object reference which is defined as an instance variable?

620


What is boolean in java?

499


Objects or references which of them gets garbage collected?

519


What is Classloader in Java?

624


What is the multi-catch block in java?

522


What is += mean in java?

531


Why java is a platform independent? Explain

523