Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing operand with + on strings

Tags:

c++

Based on seeing an apparent error in code that was compiling, I reduced it to this

#include <iostream>
#include <string>
using namespace std;

int main()
{
    const char* p = "The ";
    string s = string("Bob ") + + "world.";
    cout << s << endl;
}

I would have thought maximal munch would see "+ +" as "++" and produce an error.

like image 876
John Avatar asked May 11 '26 05:05

John


1 Answers

Maximal munch refers to processing a sequence of punctuation without any spaces.

Your code has spaces. The parser/lexer won't create a single token when there's whitespace in the middle, because the grammar doesn't allow operators to contain whitespace.

like image 83
Ben Voigt Avatar answered May 13 '26 19:05

Ben Voigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!