Naveen
Naveen

Reputation: 6008

In C++, does adding a friend to a class change its memory layout?

Also, does it matter where in the class you declare the friend ? Does it matter if you add a friend class or a friend function ?

Upvotes: 7

Views: 910

Answers (2)

stinky472
stinky472

Reputation: 6797

As mentioned already, it is purely a compile-time mechanism.

Upvotes: 1

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422132

No it doesn't. It's a purely compile-time thing: similar to access modifiers themselves.

Despite the fact that you write the declaration inside the class, you don't really add a friend to a class. You'd basically declare something else as a friend of the class and simply allow it to access the class's private members, as if they were public.

Upvotes: 19

Related Questions