Should my class declare a friend function or member function, C/C++ Programming

A: Use a member while you can and a friend when you need to.

Sometimes friends are better syntactically (e.g., in class Fred, friend functions let the Fred parameter to be second, whereas members require it to be first). Another good employ of friend functions are the binary infix arithmetic operators. For example :-  a Complex + a Complex must be defined as a friend instead of a member if you wish to allow a Float + a Complex as well (member functions don't let promotion of the left hand argument, as that would modify the class of the object it is the recipient of the member function invocation).

In other cases, select a member function on a friend function.

 

Posted Date: 3/20/2013 8:13:27 AM | Location : United States







Related Discussions:- Should my class declare a friend function or member function, Assignment Help, Ask Question on Should my class declare a friend function or member function, Get Answer, Expert's Help, Should my class declare a friend function or member function Discussions

Write discussion on Should my class declare a friend function or member function
Your posts are moderated
Related Questions
Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

the issue of oil spills

within 2 mins give me answer pllzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Precautions with function overloading Function overloading is a boon to designers, since dissimilar names for same functions need not be thought of, which often is a cumbersome

Study the given hierarchical class diagram and additional information, and answer the questions that follow: Sale Company: string unitPrice: double

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Many modern cryptography algorithms require two numbers that are coprime, or sometimes referred to as relatively prime. Two numbers are coprime if their greatest common divisor is

A: If you employ auto_ptr objects you would not need to be concerned along with heap objects not being deleted even if the exception is thrown.

Given an char variable last that has been initialized to a lowercase letter, write a loop that displays all possible combinations of two letters in the range ''a'' through last. Th