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

G

gw7rib

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.
 
V

Victor Bazarov

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top