-2

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
  • 731
  • 1
  • 6
  • 28

1 Answers1

8

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
  • 161,918
  • 27
  • 262
  • 366
Some programmer dude
  • 380,411
  • 33
  • 383
  • 585