Return a const structure by reference.
Ali Çehreli
acehreli at yahoo.com
Tue Oct 15 21:33:54 PDT 2013
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
More information about the Digitalmars-d-learn
mailing list