What is name mangling, and what problem does it solve in the context of overloading or private members?

Last updated 5 July 2026

  • Name mangling is the compiler/runtime rewriting an identifier into a unique internal name so identical source names don't collide.

  • Private members (Python): __x in class A becomes _A__x, avoiding accidental clashes with subclasses (not true security).

  • Overloading (C++): parameter types are encoded into symbol names so f(int) and f(double) become distinct linker symbols.

  • https://www.youtube.com/watch?v=0hrEaA3N3lk
  • https://dev.to/vaishnavi_sb_6fe8eed89669/understanding-name-mangling-in-python-5h19
  • https://docs.python.org/3/tutorial/classes.html
  • https://www.geeksforgeeks.org/cpp/extern-c-in-c/
All Object-Oriented Programming interview questions