-
June 22nd, 2006, 04:19 PM
#1
[RESOLVED] const corrected please in managed classes
In the introduction to the C++/CLI Langauge Specification it is stated that one of the goals used in the design of C++/CLI was to
"Provide first-class support for Standard C++ features ... for all types including CLI classes."
Unfortunately, there is a major ommision in C++/CLI, namely const correctness for managed classes. In particular, methods in these classes cannot be const (although parameters and return values can be). Experienced C++ programmers are careful to make methods const where appropriate as this provides a powerful compile-time check on program semantics.
Recent trends in C++ have stressed the importance of compile-time checks (for example, Andrei Alexandrescu's excellent book 'Modern C++ Design' and the associated library Loki.) Its a shame that C++/CLI takes a retrograde step in removing facilities for const correctness.
May I plea for const correctness to be introduced in a later version of C++/CLI.
Thank you
Nigel
Last edited by Nigel Norfolk; June 22nd, 2006 at 04:25 PM.
-
June 22nd, 2006, 04:49 PM
#2
Re: const corrected please in managed classes
Unfortunately internally the CLR has no notation of the C++ concept of 'const' so even if the compiler did allow you to define const member functions the code would not be understood by the CLR, C#, VB, or many of the other .NET languages and also in order to be able to interact the the BCL you would be forever casting away const in order to be able to call such methods.
We did try this, as we really did want to support 'const', unfortunately the result was ugly and next to unusable so we just decided to bite the bullet and disallow const as a modifier on member functions of a managed type.
Last edited by joncaves; June 22nd, 2006 at 10:39 PM.
Jonathan Caves
Visual C++ Compiler Team
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|