October 16, 2013 Return a const structure by reference. | ||||
---|---|---|---|---|
| ||||
I'm having trouble trying to return a const reference of a structure. public struct Structure { } public class A { private Structure structure; this(Structure structure) { this.structure = structure; } public ref const Structure getStructure() const { return structure; } } cannot implicitly convert expression (this.structure) of type const(Structure) to Structure |
October 16, 2013 Re: Return a const structure by reference. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Agustin | On 10/15/2013 09:28 PM, Agustin wrote: > I'm having trouble trying to return a const reference of a structure. > > public struct Structure { > } > > public class A { > private Structure structure; > > this(Structure structure) > { > this.structure = structure; > } > > public ref const Structure getStructure() const { The two consts up there have exactly the same meaning: Even the first one qualifies the function (more correctly the implicit 'this' reference). You want this: public ref const(Structure) getStructure() const { > return structure; > } > } > > cannot implicitly convert expression (this.structure) of type > const(Structure) to Structure Ali |
Copyright © 1999-2021 by the D Language Foundation