Back to listC++
LLVM RTTI Pattern
Lv.4344@mukitaro0 playsJan 2, 2026
LLVM-style RTTI (Run-Time Type Information) pattern. Lightweight alternative to dynamic_cast.
preview.cpp
1class Shape {2 public:3 enum ShapeKind { SK_Circle, SK_Square };4 ShapeKind getKind() const {5 return Kind;6 }7 Shape(ShapeKind K) : Kind(K) {}8 private:9 const ShapeKind Kind;10};11class Circle : public Shape {12 public:13 Circle() : Shape(SK_Circle) {}14 static bool classof(const Shape *S) {15 return S->getKind() == SK_Circle;16 }17};Custom problems are not included in rankings