On Monday, 18 August 2025 at 13:32:57 UTC, Brother Bill wrote:
Page 496 of Programming in D

Going in circles.  Please correct so it compiles and works.
An explanation would be helpful also.

Ali's book have a section about const member qualifier - "51.5 const member functions", but I think it should have more examples for absolute beginners. The online D reference has a better example here: https://dlang.org/spec/declaration.html#methods-returning-qualified . This example shows what happens when method is declared const (see how struct member gets const qualifier). Pay attention to the comment `// error, cannot convert const(int)* to int*` . This is exactly why you have the similar error. if Ali's reading this - it would be good to include an example showing this problem. To be fair, his book does not have this exact code - it was written by you.

So, to fix your error, you can remove the "const" method qualifier from opApply, or cast the const away from the member when you use it.

Reply via email to