There are many questions about the C++ equivalent of readonly
in C# mentioning const
. However, so far I found none that, as far as I can tell, is actually correct or even mentions the detail I am after here.
Readonly fields can be set (even multiple times) within the ctor (spec). This allows performing various operations before finally deciding on the value. Const in C++, on the other hand, behaves subtly differently (in both C++ and C#) in that it requires the final value to be available before the ctor runs.
Is there a way to still achieve the behavior of readonly
in C++?