1

While reading the source code of the vcglib, I encountered some template code like the following:

class MyVertex: public VertexSimp2<MyVertex, MyEdge, MyFace, vcg::Coord3f>{};
class MyFace: public Face<MyVertex, MyEdge, MyFace, face::VertexRef>{};

My question is: the class MyVertex inherits from a template class which has type MyVertex as a parameter, and MyFace inherits from a template class which has MyFace as a parameter. It seems to me that at the time of definition of the derived class, the base class is not well-defined. How should I decipher this piece of code?

John Z. Li
  • 1,893
  • 2
  • 12
  • 19
  • 2
    This is known as [CRTP](https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern), a fairly common pattern – Smeeheey Nov 14 '18 at 09:56

0 Answers0