C++/CLI "initonly" and "literal" vs native C++ "const" and "static const"
You know, sometime if you write the right question right, you get the answer right away.
I am reading the new C++/CLI draft (http://www.plumhall.com/C++-CLI%20draft%201.10.pdf) and I wonder why they had to invent two new keywords, the "literal" and the "initonly".
"literal" is like the C# "const" while "initonly" is like the C# readonly. In ISO C++, there is the global or static const for literal and const (in member declaration) for "initonly". So I asked: why not using "static const type var;"? And I see the answer, "static const type var" is it a literal (native C++) or "initonly" static class member (C++/CLI)?
They had to come with new keywords, just to distinguish the case of "initonly" and "literal" for static members of a class. Of course the emitted IL uses the CLI (CLR) semantic of “literal” and “initonly“, so there are some other restrictions then the C++ “const“ keyword, such as the ability to change the value of an “initonly“ member in the body of the constructor, and some restrictions of the types that you may use for the “literal“ declaration. There is another (good one) restriction for the “initonly“, you can not cast the const away.