Given that handle
is private, then the only access to it is from your class's members and its friends.
The code you have (which passes an instance of foo
to a friend function) is convoluted and unconventional compared to simply having a member function:
class foo {
WINDOW *handle;
public:
int wgetch() { return ::wgetch(handle); }
};
It appears that you're writing a C++ wrapper for a Curses WINDOW*
, so many small forwarding members would appear to be the natural approach. Note that we need the scoping operator ::
to disambiguate the wgetch
that we intend to call.
You probably ought to be aware that NCurses does include its own C++ wrappers. Although these are undocumented, we see that the definition of NCursesWindow::getch()
looks exactly like the method above (see cursesw.h
, line 953):
int getch() { return ::wgetch(w); }
You might save yourself a lot of work by using these classes.