Recently, I meet something in other's source code. I don't quite understand the template in C++. Could you help me it?
struct my_grammar : public grammar<my_grammar>
{
...
};
Why my_grammar can be used as a type parameter like it?
Best Regards,
This is an idiom called the Curiously Recurring Template Pattern - see http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern. Summarily, it provides the derived class as a policy to the base class, in similar style to Policy's used in Alexandrescu's Modern C++ Design book (highly recommended). That way, the base class can use aspects of the derived class - types, constants, methods - all resolved at compile time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With