A bracket around a function call

In the code snippet below, if I exclude the brackets around the second call std::istreambuf_iterator, I get a compilation error in the last line:

to the left of .c_str () should have a class / struct / union.

std::ifstream file("file.txt");;

std::string prog(
    std::istreambuf_iterator<char>(file),
    (std::istreambuf_iterator<char>()));
prog.c_str();

What do these parentheses do? It seems to me that they should be excluded.

+5
source share
1 answer

Without parentheses, this will be the case of the most unpleasant parsing . He would not declare a variable, but return a function std::stringcalled prog, and take these two types as parameters. If you try to call him later, you will get a linker error.

+6
source

All Articles