Here's how CRTP works because of the two-step parsing of templates. The functions of the template members are not analyzed until they are created.
EDIT: Perhaps the wording is not very accurate. What I wanted to say when the compiler sees class B : public A< B > {...}; , it passes through A< B > , notices that there exists a function B get() {...} , but does not evaluate its definition, leaving it up to the actual actual instance of the function at which point B must be a full type.
EDIT: I believe that the exact rules are described in standard section 14.6 (as Als pointed out in his answer). It deals with dependent and non-dependent names and their resolution at different times during compilation in accordance with the search for two-phase name names. However, unfortunately, the implementation of a two-stage search may differ from the standard for different compilers. The same code may compile in GCC and may not display on MSVC ++ and vice versa. Moreover, the same code can be rejected by the same compiler. In MSVC ++, I had a problem when the base class used a pointer to a derived function of the class as the default argument for its function. It did not compile under MSVC ++ and compiled under GCC (correctly). However, using the constructor of the derived class as the default parameter compiled with both compilers, even on MSVC ++. Hover over your mouse.
lapk
source share