C ++ / CRTP template code parsing

Can someone tell me how the compiler processes expressions such as

class DerivedA: public ParentTemplateClass<DerivedA>{
}

For me it looks like this:

this boy father is the "son" of this boy

I mean, it’s not obvious to me how the “parsing” of the DerivedA class can be completed WITHOUT knowing exactly the “description” of the parent class. It seems to be impossible. Therefore, the parent class must be handled in front of the children, but in such a situation the parent is dependent on the children .. and I'm stuck there.

Yes, there are some articles on the Internet that describe the use of such a thing, for example. an article about a curiously repeating template template ( http://en.wikibooks.org/wiki/More_C++_Idioms/Curiously_Recurring_Template_Pattern ), but this is not some standard or a bit. There should be a clear description of the behavior, such as streamlining operations, right?

ANSWERED: Thnx to all. Yes, ahead, it seems that the analogy seems legal for me to stop the damage to my brain. Templates are still an art for me, the reason for its hidden sublingual nature, and I can't just g ++ -E :)

+5
source share
3 answers

, class DerivedA, DerviedA. . ++ , "", ( , ). , . , , .

+6

, , DerivedA ; , . - , , , . , , , , .

, .

+3

, , , ++ , Curiously Recurring Template Pattern. , - , , ++ . , . include, :

#include "ParentTemplateClass.h" // C++ initially validates the template class definition syntax.
#include "DerivedA.h" // First use of ParentTemplateClass -
                      //   at this point it becomes fully instantiated.

The C ++ parser first checks the template syntax when it sees the template definition. Then, when the template is used as the basis of DerivedA, parsing continues and the template is completely created. This, of course, is a simplified kind of parsing that the C ++ compiler will do, and I'm sure the details depend on the compiler. See also http://womble.decadent.org.uk/c++/template-faq.html#disambiguation .

+1
source

All Articles