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 instance variables?
Explain about class in java?
When should we create our own custom exception classes?
Does java map allow duplicates?
what is heap memory?
Will the jvm load the package twice at runtime?
Write a java program that prints all the values given at command-line.
Is break statement can be used as labels in java?
Write down program for following scenario. Use java coding standard. You have array list with some words in it..we will call it as dictionary….and you have a arbitrary string containing some chars in it. You have to go through each word of dictionary and find out if that word can be constructed with the help of chars from arbitrary string given. If you find the word print it else print none.
What is polymorphism in java? What are the kinds of polymorphism?
what is a thread pool in java and why is it used?
What is an error in java?
What happens when you invoke a thread’s interrupt method while it is sleeping or waiting?
Is null a string in java?
I want to persist data of objects for later use. What is the best approach to do so?