What does this mean when using a template in C ++

I recently met something in a different source code. I do not quite understand the template in C ++. could you help me?

struct my_grammar : public grammar<my_grammar> { ... }; 

Why can my_grammar be used as a type parameter like this?

Best wishes,

+4
source share
1 answer

This is an idiom called Curiously Recurring Template Pattern - see http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern . In general, it provides a derived class as a policy to a base class, in the same style as the policy used in the Alexandrescu Modern C ++ design book (highly recommended). Thus, the base class can use aspects of the derived class — types, constants, methods — all of which are allowed at compile time.

+11
source

All Articles