Bloomberg LP Interview Question
Software Engineer / DevelopersI think template compilation happens in two phases. Phase 1 is just syntax check and phase 2 is actual instantiation. Phase 1 will catch any syntax errors
The answer is maybe, depend on your compiler. There is effectively two phases in template compilation. A syntax check and the instantiation itself. The compiler will not try to instantiate the template if it not used. So if there is nothing in main, the template is not used, so no error for the instantiation process. There might be errors for the syntax check, but the compiler may not check since the template is not used. The standard does not force the compiler to check syntax when the template is not used.
No. The template is compiled only if it is instantiated so the error is not caught until we try to create an object with the template.
- souaaz May 09, 2010