Understanding these terms in C++, Friend, Operator and Ostream.

JC0724

Weaksauce
Joined
Oct 11, 2008
Messages
105
How does these pre defined terms/functions work in C++.

Friend, Operator and Ostream.

What can you do or use these for?
 
An operator is a symbol that takes one, two, or three arguments which cause some action. In this code:

Code:
int a;
a = 37 + 59;

the plus sign is an operator that has two integer literals as arguments. The equals sign is an assignment operator, which takes the result of the plus sign operator and assigns it to the variable "a".

Operators can be overridden in C++, which lets you define them to do what you want -- maybe something you'd expect, maybe something you don't expect but find useful somehow.

"friend" establishes a relationship between two classes which pierces encapsulation. If Class A declares class B as a friend, then class B can access protected and private members of class A when it normally wouldn't be able to do so. Used sparingly, this feature is useful. Used less than judiciously, "friend" makes the object oriented design of a complex class hierarchy less intuitive and confusing.

Ostream isn't a pre-defined feature of C++; it's a part of the standard C++ library. ostream a mediator that allows some additional operations to be performed on output streams.
 
Back
Top