class A (say), having all static member functions only
class B(say) having only member functions
If i create 1000 instances of class A. As the class contains only static member functions, the memory do not increase even if there are 1 instance or 1000 instances.
However, for class B. If i create 1000 instances, will there be an increase of memory (even the slightest, may be a pointer for each object pointing to set of member functions) ?
If no, then how does the compiler keep tracks of member function information for a particular object ?
For starters, you might try outputting
sizeof(A)andsizeof(B). Butseveral things to keep in mind:
Regardless of the number or types of members, C++ forbids a class to
have a size of 0, so static members or not, each instance of
Awilltake some memory; and
The resolution of non-virtual functions is done entirely at compile
time, so there is no need for the compiler to add anything to the
class for it. (Virtual functions will typically add the size of one
pointer to the class, regardless of how many virtual functions your
class has.)