-3

I am trying to understand how defining a function as a friend function impact its placement in memory (RAM).

For example, each class has a table of all of its methods and functions. Also, virtual functions are placed in the vtable.

Where does friend functions belong?

The reason I'm concerned, is due to a [recursion] function that has been invoked a large number of times via multiple threads in my c++ code, and eventually I'm getting "v'table corruption runtime exception". which is a sign of memory corruption (as I saw here for example).

Also, when declaring this function as a regular outside-of-class function, the exception persists.

When declaring that function to be friend however (it's a bad design, but for the sake of experiment), that exception no longer pops-up.

Therefor my question about friend functions' memory location.

ThunderWiring
  • 738
  • 1
  • 7
  • 29

1 Answers1

9

friend has nothing to do with where a compiler, linker or runtime loader puts the function, it's just a keyword that tells the compiler that the function can sidestep the visibility rules of the class.

Even if a friend function is defined inline in a class it's still considered a global non-member function.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621