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
What do you know about the garbage collector in java?
What do you mean Abstraction in java?
What is bubble sorting in java?
What is Hierarchy of exception?
Explain illegalmonitorstateexception and when it will be thrown?
What is the purpose of garbage collection in java? When is it used?
How does callback work in java?
Explain about version control?
What will be the initial value of an object reference which is defined as an instance variable?
What is boolean in java?
Objects or references which of them gets garbage collected?
What is Classloader in Java?
What is the multi-catch block in java?
What is += mean in java?
Why java is a platform independent? Explain