why does a friend class need a object to access the private functions of the "otherclass" , but the "otherclass" member functions dont need an object to access the private members
Hen::Nest::Egg::access11(Hen::Nest*) can call Hen::Nest::Egg::access1() without specifying an object because they both are members of the same class. Note that that doesn't mean there is no object involved. You always need an object to call a member function. It's just that inside member functions the object that the function was called on is implicit and can be accessed by using the this keyword. What actually happens on line 17 is this: this->Hen::Nest::Egg::access1(); but you could write it as short as access1(); if you wanted.
Every program shall contain exactly one definition of every non-inline function or variable that is odr-used in that program; no diagnostic required. The definition can appear explicitly in the program, it can be found in the standard or a user-defined library, or (when appropriate) it is implicitly defined. An inline function shall be defined in every translation unit in which it is odr-used.
So functions that are not inline should only be defined once in the program. That is why you can't define it in the header because that would mean it will be defined once for each source file (.cpp) that includes it.
Inline functions on the other hand has to be defined for each source file that calls the function. This more or less forces inline functions to be defined in headers.
Why this inconsistency you might ask. I think it has to do with the fact that it's much harder for the compiler to inline a function if the definition is not available. Remember that each source file is compiled in separation with no knowledge of other source files and not until everything has been compiled it is linked together to create an executable. Modern compilers usually can make it work by using something called link-time optimizations (e.g. GCC's -flto flag) but traditionally compilers have not had this feature and you still have to enable it because it makes the compilation process slower.
Sorry if I am not able to get your last post properly but ...
I know I can define inline functions in header files but does that mean, inside inline functions, u can force access of private members without an object? i mean other than "this"
and does implicit vs explicit have a performance difference in terms of run time and compile time
for eg:
is there a run time or compile time difference seen even by a small margin if i used any one of the following in my 1st
post in this topic:
Sorry, I might have misinterpreted your question. I thought you where shifting to a new question about inline.
No inline functions does not change how you can access things. The same rules apply.
Doing something implicit or explicit doesn't affect runtime performance at all.
To explain your original question
Surround is a friend of Surround::SecondWithin which means that the members of Surround are allowed to access the private members of Surround::SecondWithin.
Surround::FirstWithin is a member of Surround so it is perfectly fine for Surround::FirstWithin::value() to access Surround::SecondWithin::s_variable.