Braces or Parenthesis?

When I passed in the window dimensions I expected to do it with parenthesis.

Character Knight(WindowDimensions[0], WindowDimensions[1]);

This ran and worked.
But when he did it, he used curly braces instead.

Character Knight{WindowDimensions[0], WindowDimensions[1]};

Can anyone offer more clarity here?

1 Like

The top example looks like a method and the bottom example looks something like an object literal, if memory serves.

1 Like

Because in the end, the braced initialization (bottom) actually calls the Constructor (top) in the background.

Both end up creating and initializing the Knight as a Character object. Braced initialization has the added benefit of forcing variables to be initialized to default values. Though when it comes to classes the benefit is not really seen.