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 are different ways in which a thread can enter the waiting state? : Java thread
What is the difference between int and integer in java?
What is the difference between declaration and definition in java?
What is JFC?
What does provide mean construction?
Can an anonymous class be declared as implementing an interface and extending a class in java programming?
What is java thread dump, how can we get java thread dump of a program?
how its run?
Can we use different return types for methods when overridden?
Can we override constructors?
Why spring singleton is not thread safe?
Why can't we make a class private in java?
How do you override a method in java?
What is multi level inheritance in java?
What is the difference between class & structure?