2

In c++ what is the difference between initializing an object with round or angled braces like in this example?

#include <iostream>
#include <string>

int main()
{
    std::string x = "abc";

    std::string c(x);
    //std::string c{x};

    std::cout << "String c " << c;

    return 0;
}
NathanOliver
  • 171,901
  • 28
  • 288
  • 402
cherry aldi
  • 327
  • 1
  • 10
  • 1
    Relevant: [Why is list initialization (using curly braces) better than the alternatives?](https://stackoverflow.com/q/18222926/580083) – Daniel Langr Oct 05 '18 at 13:13
  • Depend if there is constructor with `std::initializer_list` (as `std::vector{1, 2, 3}` vs `std::vector(4, 0)`) and allowed/disallowed narrowing especially. – Jarod42 Oct 05 '18 at 13:13

0 Answers0