A operator + (const A& otherObject) const; |Overloading Operators| What the mean
ID: 3877169 • Letter: A
Question
A operator + (const A& otherObject) const;|Overloading Operators|
What the meaning of the & and the two const?
A A::operator + (const A& otherObject) const {
} In this function def why do we need the class name twice? A A::operator? A operator + (const A& otherObject) const;
|Overloading Operators|
What the meaning of the & and the two const?
A A::operator + (const A& otherObject) const {
} In this function def why do we need the class name twice? A A::operator?
|Overloading Operators|
What the meaning of the & and the two const?
A A::operator + (const A& otherObject) const { A A::operator + (const A& otherObject) const {
} In this function def why do we need the class name twice? A A::operator?
Explanation / Answer
A operator + (const A& otherObject) const;
in this function declaration A is the return type of function.Now in defination outside the class
A A::operator + (const A& otherObject) const
{
}
we use :: (resolution operator) with Class name A. Because function (operator +) is member of A, when referring to it from outside the class, we have to qualify their names. If we had not put the A:: qualification on the names, we would be defining some new functions in the global scope, rather than as members of A.
And another A in defination is return type of function.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.