Cocos2d-x C++ Tips


Java has instanceof to check class type, Objective-C also has ==.
C++ doesn’t have that kind of method by platform

Use dynamic cast

template <typename Of, typename What>
inline bool instanceof(const What w) {
  return dynamic_cast<const Of*>(w) != 0;

How to use?

instanceof<Scene>(node);  // Return true or false

Scene is class name, node is instance.