Why can't I copy a const struct?

Atila Neves atila.neves at gmail.com
Fri Nov 15 07:12:53 PST 2013


     private struct DummyStruct {
         int[] a;

         this(this) {
             a = a.dup;
         }
     }


     void main() {
         const dummy1 = DummyStruct();
         DummyStruct dummy2 = dummy1;
     }

     struct_copy.d(12): Error: conversion error from 
const(DummyStruct) to DummyStruct

Surely I should be able to copy it and use the mutable version as 
I please, no? I'd understand if the postblit constructor wasn't 
defined...

Atila


More information about the Digitalmars-d-learn mailing list