On 9/11/07, <b class="gmail_sendername">Janice Caron</b> &lt;<a href="mailto:caron800@googlemail.com">caron800@googlemail.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br><br>the admittedly now out-of-date documentation for const says, of class<br>member functions, that the syntax for member functions which do not<br>modify member variables should be<br><br>invariant void foo()<br><br>
Does that mean that all &quot;getter&quot; property functions will have to be<br>re-prototyped?<br><br>As in<br><br>class C<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;private int my_x;<br>&nbsp;&nbsp;&nbsp;&nbsp;invariant int x() { return x; }<br>}<br><br>?<br></blockquote>
</div><br><br><br>So, if I&#39;ve understood this correctly, the syntax for a member function which (a) does not modify any member variables, and (b) returns an invariant pointer, would be<br><br>class C<br>{<br>&nbsp;&nbsp;&nbsp; invariant invariant int * f() { /* body */ }
<br>}<br><br>The first &quot;invariant&quot; tells you (a); the second &quot;invariant&quot; tells you (b). This leads me to conlude that<br><br>class C<br>
{<br>
&nbsp;&nbsp;&nbsp; invariant int * f() { /* body */ }<br>
}<br>
<br>
is surely ambiguous. It could be interpreted either as &quot;f is a member function of C which does not modify any of C&#39;s member variables, and which returns a pointer to int&quot;, or &quot;f is a member function of C which is permitted to modify C&#39;s member variables, and which returns an invariant pointer to int&quot;.
<br><br>It is precisely in order to avoid this ambiguity that C++ syntax has the &quot;const&quot; at the end, as in<br><br>/* C++ */<br>class C<br>{<br>&nbsp;&nbsp;&nbsp; int * f() const { /* body */ }<br>
&nbsp;&nbsp;&nbsp; const int * f() { /* body */ }<br>
&nbsp;&nbsp;&nbsp; const int * f() { /* body */ } const<br>
}<br><br>In the above C++ example, the first function declares a member function of C which does not modify any of C&#39;s member variables, and which returns a pointer to int, while the second function returns  a member function of C which is permitted to modify C&#39;s member variables, and which returns a const pointer to int. And for completeness, the third one declares a member function of C which does not modify any of C&#39;s member variables, and returns a const pointer to int.
<br><br>I will freely admit, I don&#39;t like C++&#39;s syntax either. The whole &quot;const at the end&quot; business is confusing. (It&#39;s not so confusion now that I&#39;ve got used to it, but it was confusing at first). I don&#39;t know whether or not D can do better, but I certainly don&#39;t like the idea of declarations being ambigous.
<br><br>I have no suggestion for how to fix this, however I bring to your attention the fact that it might need fixing.<br><br>