In some cases, it is possible to call a class member function without creating the class object.
In the following example, the program will print "hello world" although class A has never been created. When the program enters the "PrintMe" function, the "this" pointer is zero. This is fine as long as you don't access data members through the "this" pointer.
#include <stdio.h>
class A {
public:
void PrintMe();
};
void A::PrintMe()
{
printf("Hello World\n");
}
void main()
{
A* p = 0;
p-<PrintMe();
}
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible.
Submit your tip here.