I have a helper class in my program that has many static functions used in different classes of my program. For example.
helper.h :
Class helper { public: static void fn1 () { } static void fn2(); }
The helper has only static member functions. Thus, no helper objects are created by other modules. Helper functions are used in other modules, such as:
A.cpp
#include "helper.h" A::foo() { helper::fn1(); helper::fn2(); }
B.cpp
#include "helper.h" B::foo() { helper::fn1(); helper::fn2(); }
Does the compiler create separate copies of helper functions in A.cpp and B.cpp ? I read some early posts, and I put together the answers that such a compiler would create. But when I print the address fn1 and fn2 as printf("Address of fn1 is %p\n", &helper::fn1); and printf("Address of fn1 is %p\n", &helper::fn1); from A.cpp and B.cpp , I get the same address. Now I am confused. Can someone clarify if I missed something.
The reason I'm worried about multiple copies of helper functions (if this happens) is because we are trying to reduce the size of the executable and want to optimize it.
c ++ static-members
cppcoder Mar 20 2018-11-21T00: 00Z
source share