3

コンパイル中のコードに明らかなエラーが見られたことに基づいて、私はそれをこれに減らしました

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

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

最大ムンクは「+ +」を「++」と見なし、エラーを生成すると思っていたでしょう。

4

4 に答える 4

2

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.

于 2012-10-11T15:30:25.673 に答える
2

「最大マンチ」が何をするのかを誤解しています-それは魔法のように演算子を連結しません-なり+ +ません++。後者は に適用されますが"world."、それだけです:

string s = string("Bob ") + (+"world.");

のことを考える

int x = +1;
于 2012-10-11T15:31:45.030 に答える
1

いいえ、+ +と同じではありません+。最後の部分式は+"world."であり、これはポインターの単項+であり、何もしません。

于 2012-10-11T15:34:07.197 に答える
0

2 つの の間にスペースがあるため、語彙アナライザーでは+それぞれ+が異なるトークンとして扱われます。

于 2012-10-11T15:31:27.107 に答える