You are here:

C++/Shift-Opeator Overloading

Advertisement


Question
When Shift operators are overloaded for operating on user-defined data types, they are declared as friend. Why is that so with these operators while other operators like unary and binary are not?

Thanks in Advance for your help.  

Answer
T, Thank you for your question.

There is no need, in general, to use "friend" in overloaded operator or function definitions.

"friend" is neccessary in a class declaration when a member function needs to reference a private or protected member declaration in another class.

Please give me an example of a definition that puzzles you.

David Spector

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Spector

Expertise

Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.

Experience

I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Publications
Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

Education/Credentials
ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 About.com. All rights reserved.