What means ({}); Mean value in C ++?

AFAIK {}defines a new area, so what does it define?

({});

The compiler compiles this program well:

#include <iostream>
#include <string>

int main()
{
  std::string name;
  std::cout << "What is your name? ";
  {
     ({}); 
  }
  getline (std::cin, name);
  std::cout << "Hello, " << name << "!\n";
}

When I replace ({});with ();, the compiler cannot compile the program.

Why ({});is it working well but ();not working?

I tested the program on cpp.sh. It compiles fine.

+6
source share
1 answer

({});not part of standard C ++. As @HolyBlackCat correctly said, this is a compiler extension. Use -pedantic-errorsto disable compiler extensions.

See the demo here when compiling tog++

. vc++.

+8

Source: https://habr.com/ru/post/1016568/


All Articles