4

I'm working on a project where I have created a class named Friend and just noticed that Xcode colors it like a keyword or a modifier. Can I use it like I did in my code, or it has other purpose?

enter image description here

Updated: It seems this is already answered here:

Why does the xcode IDE think `friend` is a reserved-word

But thanks for the help guys!

Community
  • 1
  • 1
Endanke
  • 867
  • 13
  • 24

2 Answers2

2

C++ provides the friend keyword to do just this. Inside a class, you can indicate that other classes (or simply functions) will have direct access to protected and private members of the class. When granting access to a class, you must specify that the access is granted for a class using the class keyword:

friend class aClass;

Note that friend declarations can go in either the public, private, or protected section of a class--it doesn't matter where they appear. In particular, specifying a friend in the section marked protected doesn't prevent the friend from also accessing private fields.

1

friend is a keyword used in C++, for creating friend functions.
Objective C supports both C and C++ keywords, so it is better to rename that parameter.

More about friend functions : friend function in C++

Midhun MP
  • 103,496
  • 31
  • 153
  • 200