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 is array command?
What is run time allocation?
What is ternary operator? Give an example.
What are the three best choices for a development environment?
What is a parameter in a function?
Explain restrictions for using anonymous inner classes?
What is jvm? Why is java called the platform independent programming language?
When can an object reference be cast to an interface reference in java programming?
How do you declare an array in java?
Is java same as core java?
What does flag mean in java?
What’s meant by anonymous class?
Is void a data type in java?
Is hashmap thread safe?
Why do we need autoboxing in java?