digitalmars.D.learn - `This` reference not accessible when overloading an operator?
- Enjoys Math (12/12) Jan 21 2020 I have an Integer class in integer.d. A RationalNumber class in
- Mathias Lang (3/15) Jan 21 2020 The error message says that the constructor of `RationalNumber`
- Steven Schveighoffer (4/20) Jan 21 2020 Do you have a static somewhere that's affecting this? A more complete
I have an Integer class in integer.d. A RationalNumber class in rational_number.d, and they each import each other (so that could be the issue). However, this is not working: Symbol opBinary(string op : "/")(const Integer z) const { return new RationalNumber(this, z); } Getting: Error: class `rational_number.RationalNumber` member `this` is not accessible Error: template instance `integer.Integer.opBinary!"/"` error instantiating
Jan 21 2020
On Tuesday, 21 January 2020 at 20:48:44 UTC, Enjoys Math wrote:I have an Integer class in integer.d. A RationalNumber class in rational_number.d, and they each import each other (so that could be the issue). However, this is not working: Symbol opBinary(string op : "/")(const Integer z) const { return new RationalNumber(this, z); } Getting: Error: class `rational_number.RationalNumber` member `this` is not accessible Error: template instance `integer.Integer.opBinary!"/"` error instantiatingThe error message says that the constructor of `RationalNumber` is not accessible, not the `this` reference of `integer.Integer`.
Jan 21 2020
On 1/21/20 3:48 PM, Enjoys Math wrote:I have an Integer class in integer.d. A RationalNumber class in rational_number.d, and they each import each other (so that could be the issue). However, this is not working: Symbol opBinary(string op : "/")(const Integer z) const { return new RationalNumber(this, z); } Getting: Error: class `rational_number.RationalNumber` member `this` is not accessible Error: template instance `integer.Integer.opBinary!"/"` error instantiatingDo you have a static somewhere that's affecting this? A more complete code example might help. -Steve
Jan 21 2020