Friend functions - do I need to include the whole prototype?

Discussion in 'C++' started by gw7rib@aol.com, Nov 22, 2006.

  1. Guest

    Suppose I have a function, whose protoype is somewhat complicated, for
    example, with some #defines and typedefs, it looks like this:

    INT_PTR CALLBACK PropDlgProc(HWND hDlg, UINT message, WPARAM wParam,
    LPARAM lParam);

    and I'm not allowed to make it a member function <OT> because it's a
    dialog box function </OT>.

    I want to make it a friend of my class, because it updates class
    members and I don't really want the class members to be public.

    Can I do something simple like:

    friend PropDlgProc;

    or does it have to be the full-blown:

    friend INT_PTR CALLBACK PropDlgProc(HWND hDlg, UINT message, WPARAM
    wParam, LPARAM lParam);

    It seems a bit unnecessary to spell it all out again, particularly as
    I'm going to spell it all out a third time when I get to the function
    body.

    Can anyone advise?

    TIA
    Paul.
     
    , Nov 22, 2006
    #1
    1. Advertising

  2. wrote:
    > Suppose I have a function, whose protoype is somewhat complicated, for
    > example, with some #defines and typedefs, it looks like this:
    >
    > INT_PTR CALLBACK PropDlgProc(HWND hDlg, UINT message, WPARAM wParam,
    > LPARAM lParam);
    >
    > and I'm not allowed to make it a member function <OT> because it's a
    > dialog box function </OT>.
    >
    > I want to make it a friend of my class, because it updates class
    > members and I don't really want the class members to be public.
    >
    > Can I do something simple like:
    >
    > friend PropDlgProc;
    >
    > or does it have to be the full-blown:
    >
    > friend INT_PTR CALLBACK PropDlgProc(HWND hDlg, UINT message, WPARAM
    > wParam, LPARAM lParam);
    >
    > It seems a bit unnecessary to spell it all out again, particularly as
    > I'm going to spell it all out a third time when I get to the function
    > body.
    >
    > Can anyone advise?


    I think you have to spell it out since just a name can represent several
    overloaded functions, and it would be unclear which one of them you
    intend to make a friend.

    BTW, why can't you supply proper accessors to your private data? There
    would be no need for friendship...

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Nov 22, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. \A_Michigan_User\
    Replies:
    2
    Views:
    942
    \A_Michigan_User\
    Aug 21, 2006
  2. Andreas Bogenberger
    Replies:
    3
    Views:
    1,014
    Andreas Bogenberger
    Feb 22, 2008
  3. June Lee
    Replies:
    2
    Views:
    849
    Jim Cobban
    Apr 13, 2008
  4. Replies:
    9
    Views:
    237
    Thomas 'PointedEars' Lahn
    May 26, 2006
  5. Replies:
    3
    Views:
    290
Loading...

Share This Page