|
|
|
|
|
by tialaramex
1707 days ago
|
|
In C++ you're only ever one missing "explicit" from introducing such problems. Suppose I call fire(bob). Programmers from other languages might reason that since fire is a function which takes a Person, bob must be a Person. Not in C++. In C++ the compiler is allowed to go, oh, bob is a string and I can see that there's a constructor for Person which takes a string as its only argument, therefore, I can just make a Person from this string bob and use that Person then throw it away. To "fix" the inevitable cascade of misery caused by this "feature" C++ then introduces more syntax, an "explicit" keyword which means "Only use this when I actually ask you to" rather than as a sane person might, requiring an implicit keyword to flag any places you actually want this behaviour to just silently happen. This way, hapless, lazy or short-sighted programmers cause the maximum amount of harm, very on-brand for C++. See also const. |
|