www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Return a const structure by reference.

reply "Agustin" <agustin.l.alvarez hotmail.com> writes:
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
Oct 15 2013
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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
Oct 15 2013