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 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

Eclipse CDT: Symbol ‘cout’ could not be resolved

Most likely you have some system-specific include directories missing in your settings which makes it impossible for indexer to correctly parse iostream, thus the errors. Selecting Index -> Search For Unresolved Includes in the context menu of the project will give you the list of unresolved includes which you can search in /usr/include and add … 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