C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 24)
24.
What is correct about the following program?
#include<iostream.h>
class Addition
{
int x;
public:
Addition()
{
x = 0;
}
Addition(int xx)
{
x = xx;
}
Addition operator + (int xx = 0)
{
Addition objTemp;
objTemp.x = x + xx;
return(objTemp);
}
void Display(void)
{
cout<< x << endl;
}
};
int main()
{
Addition objA(15), objB;
objB = objA + 5;
objB.Display();
return 0;
}
Discussion:
3 comments Page 1 of 1.
Rohan said:
2 years ago
Addition operator + (int xx )
{
Addition objTemp;
objTemp.x = x + xx;
return(objTemp);
}
Now this fun will run because it does not have any default argument.
NOTE: When we overload an operator it should not contain any default argument.
{
Addition objTemp;
objTemp.x = x + xx;
return(objTemp);
}
Now this fun will run because it does not have any default argument.
NOTE: When we overload an operator it should not contain any default argument.
Rahul said:
1 decade ago
Because rule is that overloaded operator cannot have default argument.
(1)
Abhishek said:
1 decade ago
Can anyone explain me operator + can not have default argument.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers