static friend function

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

static friend function

 
0
  #1
Oct 4th, 2005
We cannot have static friend function...is it because

1.since static member functions can access only static data members...whereas friend function can access all the members.

2.friend function also require an object to access the members...wheeras static member functions can not.

3.One more thing....since friend functions are non-member functions....and static functions are member functions

Am i right.....if there is an error..plz correct....or a better or different reason ...the plz add
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: static friend function

 
0
  #2
Oct 4th, 2005
  1. static int func(); // proto for a static func
  2.  
  3. class AClass
  4. {
  5. friend int func(); // can be a friend and retains its static linkage
  6. friend int anotherfunc(); // assumed to have external linkage
  7. };
Static funcs can be friends. A static member can also be used to access an objects internals as long as it recieves a this pointer explicitly when its called. This trick is often used when wrapping the win32 api up to have a static wndproc pass down the messages to a virtual wndproc. This is done usually by storing the this pointer as a windowlong and retrieving it in the static func so that the virtual wndproc can be called.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2424 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC