Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 49877ddc authored by ROUVREAU Vincent's avatar ROUVREAU Vincent Committed by GILLES Sebastien
Browse files

Remove semicolon at the end of function declaration, and explains why it is...

Remove semicolon at the end of function declaration, and explains why it is required to add a semicolon at the end of a struct
parent c10a1de3
......@@ -22,11 +22,11 @@
#include <cmath> // For std::sqrt
double norm(double v_x, double v_y, double v_z)
return std::sqrt( v_x * v_x + v_y * v_y + v_z * v_z );
double v1_x, v1_y, v1_z;
v1_x = 1.;
v1_y = 5.;
......@@ -124,10 +124,36 @@
Let's also highlight the `.` syntax which allows to access the attributes of an object (e.g `v1.x`).
%% Cell type:markdown id: tags:
### The semicolon at the end of a `struct`
This comes historically from the C, where a `struct` is considered as a type declaration and it allows to do:
**Xeus-cling issue:** Here cling doesn't manage to compile it but it is accepted rightfully by a full-fledged compiler (see for instance [@Coliru](
%% Cell type:code id: tags:
``` C++17
struct Vector
double x;
double y;
double z;
} v1; // Here the struct is declared and at the same time an object v1 is created
v1.x = 1.;
v1.y = 5.;
v1.z = -2.;
%% Cell type:markdown id: tags:
This is the reason why a semicolon is always required at the end of a `struct` or a `class` declaration.
%% Cell type:markdown id: tags:
## Passing a struct to a function
In the `norm` function above, we passed as argument an object of `Vector` type by value. When we introduced functions, we saw there were three ways to pass an argument:
* By value.
* By reference.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment