Mentions légales du service

Skip to content
Snippets Groups Projects

An example of constructor call with braces - empty braces to fix the most vexing parse problem

1 file
+ 20
0
Compare changes
  • Side-by-side
  • Inline
I advise you to read this very interesting [FluentCpp post](https://www.fluentcpp.com/2018/09/28/auto-stick-changing-style/) about this syntax which ponders about the relunctance we might have to embrace evolution of our languages - so the reading is of interest even for developers using other languages.
I advise you to read this very interesting [FluentCpp post](https://www.fluentcpp.com/2018/09/28/auto-stick-changing-style/) about this syntax which ponders about the relunctance we might have to embrace evolution of our languages - so the reading is of interest even for developers using other languages.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
 
### "braces" (`{}`) for constructor calls
 
 
Another alternate syntax that removes the ambiguity is the use of braces (`{}`):
 
%% Cell type:code id: tags:
 
``` C++17
 
#include <iostream>
 
 
{
 
Vector v1{}; // Constructor Vector()
 
std::cout << v1.norm() << std::endl;
 
 
Vector v2{5., 6., -4.2}; // The other constructor Vector(double x, double y, double z)
 
std::cout << v2.norm() << std::endl;
 
}
 
%% Cell type:markdown id: tags:
Loading