This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
cpp:syntax:struct [2021/03/21 10:40] bmonsuez [L'initialisation des structures en C++] |
cpp:syntax:struct [2022/11/18 10:47] (current) |
||
---|---|---|---|
Line 56: | Line 56: | ||
int denominator; | int denominator; | ||
| | ||
- | rational(int theNumerator): numerator(theNumerator) {} | + | rational(): numerator(0), denominator(0) {} |
+ | rational(int theNumerator): numerator(theNumerator), denominator(0) {} | ||
rational(int theNumerator, int theDenominator) | rational(int theNumerator, int theDenominator) | ||
{ | { | ||
Line 89: | Line 90: | ||
</code> | </code> | ||
- | Et donc, une [[cpp:syntax:exception|exception]] de type [[https://en.cppreference.com/w/cpp/error/invalid_argument|std::invalid_argument]] sera généré. | + | Et donc, une [[cpp:syntax:exception|exception]] de type [[https://en.cppreference.com/w/cpp/error/invalid_argument|std::invalid_argument]] sera générée. |
- | + | ||
- | + | ||
- | Cependant, nous avons deux cas de figure: | + | |
- | + | ||
- | * soit il existe un compilateur prenant les deux arguments de | + | |