You are not logged in.
Pages:: 1
#1 2016-01-19 05:39:19
Operator Overloading Quiz Question.
Programming Languages Quizzes Operator Overloading
Question:
#include<iostream>
using namespace std;
class Point {
private:
int x, y;
public:
Point() : x(0), y(0) { }
Point& operator()(int dx, int dy);
void show() {cout << "x = " << x << ", y = " << y; }
};
Point& Point::operator()(int dx, int dy)
{
x = dx;
y = dy;
return *this;
}
int main()
{
Point pt;
pt(3, 2);
pt.show();
return 0;
}
Option A):
x = 2, y = 3
Option B):
Compiler Error
Option C):
x = 3, y = 2
Correct Answer is Option C):
x = 3, y = 2
Explanation:
This a simple example of function call operator overloading. The function call operator, when overloaded, does not modify how functions are called. Rather, it modifies how the operator is to be interpreted when applied to objects of a given type. If you overload a function call operator for a class its declaration will have the following form:
return_type operator()(parameter_list)
Online Web Tutorials And Interview Questions With Answers Forum:
https://globalguideline.com/forum/
Offline
2016-01-19 05:39:19
- Advertisement
- Ads By Google
Re: Operator Overloading Quiz Question.
\n
Pages:: 1