22.14. Name-mangling

When a compiler processes C++ code it changes the names of functions to include information about the types of the function’s arguments. This process, normally invisible, is called ‘name-mangling’.

You most often notice the effects of name-mangling when you put a prototype of a class method in a header file, but then fail to implement the method in any of your project’s *.cpp files. The project will compile all right, but at the very end, you will get a linker message. Thus, if you were to leave out the code for the cCritter method int cCritter::move(Real dt), you would get a linker error like the following.

 popview.obj : error LNK2001: unresolved external symbol “public: int __thiscall cCritter::move(float)” (?move@cCritter@@QAEHM@Z) ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.