C++ equivalent of java’s instanceof

Try using: This requires your compiler to have rtti support enabled. EDIT: I’ve had some good comments on this answer! Every time you need to use a dynamic_cast (or instanceof) you’d better ask yourself whether it’s a necessary thing. It’s generally a sign of poor design. Typical workarounds is putting the special behaviour for the … Read more

Is it still safe to delete nullptr in c++0x?

5.3.5/7 says: If the value of the operand of the delete-expression is not a null pointer value, the delete-expression will call a deallocation function (3.7.4.2). Otherwise, it is unspecified whether the deallocation function will be called. And 3.7.4.2/3 says: The value of the first argument supplied to a deallocation function may be a null pointer … Read more

How do I check if a Key is pressed on C++

As mentioned by others there’s no cross platform way to do this, but on Windows you can do it like this: The Code below checks if the key ‘A’ is down. In case of shift or similar you will need to pass one of these: https://msdn.microsoft.com/de-de/library/windows/desktop/dd375731(v=vs.85).aspx The low-order bit indicates if key is toggled. Oh and … Read more

How to use bitmask?

Bit masking is “useful” to use when you want to store (and subsequently extract) different data within a single data value. An example application I’ve used before is imagine you were storing colour RGB values in a 16 bit value. So something that looks like this: You could then use bit masking to retrieve the … Read more

Member function with static linkage

The keyword static has several different meanings in C++, and the code you’ve written above uses them in two different ways. In the context of member functions, static means “this member function does not have a receiver object. It’s basically a normal function that’s nested inside of the scope of the class.” In the context … Read more

Array of Linked Lists C++

That returns a bunch of unallocated pointers. Your top level array is fine, but its elements are still uninitialized pointers, so when you do this: You invoke undefined behavior. You’re dereferencing an uninitialized pointer. You allocated the array properly, now you need to allocate each pointer, i.e., As an aside, I realize that you’re learning, … Read more