The reason is because it was never constructed. Notice, though, that you are deferencing a null pointer, so it could well crash. The reason why it might not is because your class has no state - the
hash function is presumably already in memory somewhere, and all you are doing is calling it. If it modified state then it would be another story...
As for why it is different, is because in your second example you construct the instance first before sending it. Also, your two callings of the function are actually identical, but one is split over two lines and the other isn't.
On a slightly unrelated note, this doesn't seem to be a good time for a Singleton pattern. Because your
hash function does not access (or modify) state, there is no need for it to be part of a class. Rather, it should be a normal function. If you feel like it HAS to be in a class for some reason, it should be something like this:
1 2 3 4
|
class CDoubleHashing {
public:
static int hash(...) { ... }
};
|
Though, unless there are other reasons to do with your code base you have, I can't think of a reason as to why you would need to do that...