Struct copy constructor with inout

Paul Backus snarwin at gmail.com
Tue Nov 14 13:58:17 UTC 2023


On Tuesday, 14 November 2023 at 13:41:32 UTC, Steven 
Schveighoffer wrote:
> ```
> Error: copy constructor `testinoutctor.S1.this(ref const(S1) s) 
> const` is not callable using argument types `(const(S1))`
> ```
>
> I'm not sure what this means. There shouldn't be a copy being 
> made here, as the thing is already const. I don't understand 
> this error, and it looks like a bug to me.

The error is saying that the copy constructor expects a `const` 
`this` argument, but you're passing a mutable `this` argument.

It's confusing because (a) the `this` argument is hidden and 
doesn't appear in the parameter list, and (b) there's no explicit 
"mutable" qualifier. So when it prints out the list of argument 
types that were actually passed, the `this` argument (`S1 ss1`) 
gets printed as an empty string.

It's easier to see if you compare the actual and expected 
argument lists side-by-side

     Expected: (ref const(S1) s) const
     Actual:   (    const(S1)  )
                                 ^^^^^
                      Mismatched 'this' argument


More information about the Digitalmars-d-learn mailing list