Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

Alex Parrill via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 7 13:26:55 PDT 2016


On Monday, 6 June 2016 at 21:55:00 UTC, ag0aep6g wrote:
> On 06/06/2016 11:25 PM, Alex Parrill wrote:
>> You might be able to get away with casting the const away, if 
>> you are
>> sure it won't modify the hash or equality check.
>
> Casting away const and then mutating has undefined behavior. 
> The compiler is free to assume that it doesn't happen.
>
> Be aware that you're working outside of the specified language 
> if you do it. You rely on the compiler producing code that 
> works in your favor when it has no obligation to do so.
>
> I don't think we should ever suggest relying on undefined 
> behavior here in D.learn.

Yes, you are correct. I was mixing up C const rules with D.

Unfortunately there does not seem to be an easy solution to this 
problem. The best solution might be to use an array of pairs 
instead of a hash table, but that may have a performance impact.


More information about the Digitalmars-d-learn mailing list