member, non-member friend, non-member non-friend?

Sorry to bother you with it, but I couldn't find a suitable example online
so I had to come here.

So, for a simple example of an advanced data type, how would you implement
a member function, non-member friend function, and a non-member non-friend
function.

I don't mind what the example be, as long as it is quit simple one.

Appreciated,
Abdou.
1
2
3
4
5
6
class Aclass
{
  void member_function() { }
  friend void non_member_friend_function() { }
  static void non_member_non_friend_function() { }
};
A non-member function is a function that is not a member of a class. In the example above non_member_non_friend_function() is a static member function.

To fix the example you can move the function outside of the class definition.

1
2
3
4
5
6
7
class Aclass
{
  void member_function() { }
  friend void non_member_friend_function() { }
};

static void non_member_non_friend_function() { }

Note that the friend function is not a member function even if you define it inside the class definition.
Last edited on
@Peter87

Okay: Everything within the class can be considered a member. Actually from a static function you cannot access non static members.

A friend function are not accessed via its scope resolution operator (which is basically the difference to static functions).
Topic archived. No new replies allowed.