php hit counter

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
difference between member functions,non member functions and friend functions ?
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#2
In C++, we know that private members cannot be accessed from the outside class.
That is a non-member function cannot have an access to the private data of a class.
However there could be a situation where we would like two classes to share a particular function.
For example consider a case where two classes, manager and scientist have been defined.
We would like to use a function income_ tax () to operate on the objects of both these classes.
In such situation, C++ allows the common function to be made friendly with both the classes. Such a function needs not be member of any these classes.
To make outside function friendly to a class, we have to simply declare this function as a friend of a class as shown below:
Class ABC
{
……
…..
Public:
……..
……..
Friend void xyz (void); //declaration
};

When the function is logically coupled with the class (like your maze connectedness example)
When the function needs to access private or protected members, it's better to make it a member than a friend. when it's a generic function that can be templatized to naturally work on other classes (look at the <algorithms> header for good example) .

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Messages In This Thread
difference between member functions,non member functions and friend functions ? - by Vuhelper - 05-02-2011, 04:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how often do we require to use inline functions and macros. their importance in c++ Vuhelper 0 8,542 05-31-2012, 01:49 AM
Last Post: Vuhelper
  What is the difference among calloc function ,malloc function and recalloc function? Vuhelper 0 34,675 05-31-2012, 01:46 AM
Last Post: Vuhelper
  What is difference among Binary Tree, Complete Binary Tree and Binary Search Tree? Vuhelper 2 4,452 03-18-2012, 12:47 AM
Last Post: Xpert
  Explain the difference b/w Null Pointer and Null Nodes? C++ 2012 Vuhelper 0 2,011 01-06-2012, 12:24 AM
Last Post: Vuhelper
  What is the difference b/w Inorder Traversal and Inorder Successor? 2012 Vuhelper 0 1,848 01-06-2012, 12:23 AM
Last Post: Vuhelper
  what is the difference between 1. Double Right-Left Rotation 2. Double Left-Right Rot Vuhelper 0 2,085 01-04-2012, 10:37 PM
Last Post: Vuhelper
  What is the difference between “object = this->object” and “this->object=object”? Vuhelper 0 4,110 01-04-2012, 10:17 PM
Last Post: Vuhelper
  What is difference between a complete binary tree and strictly binary tree? Vuhelper 0 4,554 11-05-2011, 05:24 PM
Last Post: Vuhelper
  what is difference between *a.b and (*a).b ? Vuhelper 0 2,752 11-05-2011, 05:23 PM
Last Post: Vuhelper
  what is difference between int* b and int *b? Vuhelper 0 2,255 11-05-2011, 05:20 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support