Maximal Munch


Beginners in C++ template programming commonly end up writing following kind of code, which is not understood by compilers.



// Following gives compilation errors:
std::vector
<std::vector<int>> vecOfVecOfInt;

// Corrected code – observe space betwen two consecutive “>”s.
std::vector<std::vector<int> > vecOfVecOfInt;


Due to “maximal munch” rule of compiler, the token “>>” is read as right-shift operator. Therefore, in nested templates in above example “>>” is not parsed as desired by the programmer. As a solution, programmer need to put a space between two consecutive “>”s.
Maximal Munch Maximal Munch Reviewed by Sourabh Soni on Sunday, January 31, 2010 Rating: 5

No comments

Post a Comment