www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Override property

reply Aldo <aldocd4 outlook.com> writes:
Hello,

can you tell me if this compilation error is normal ?

class Texture
{
	public this()
	{
		
	}
}

class Control
{
	private Texture m_texture;
	
	 property
	{
		public Texture texture()
		{
			return this.m_texture;
		}
		
		public void texture(Texture value)
		{
			this.m_texture = value;
		}
	}
}

class PictureBox : Control
{
	 property
	public override void texture(Texture value)
	{
		writeln("override");
		this.m_texture = value;
	}
}

import std.stdio;
	
void main()
{
	auto picture = new PictureBox();
	
	writeln(picture.texture is null);
	
}

Error: function f340.PictureBox.texture (Texture value) is not 
callable using argument types ()

Complete code : https://dpaste.dzfl.pl/aa7bf25548e8

I can't use property getter if I override the setter property.
May 10
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 10 May 2017 at 16:40:09 UTC, Aldo wrote:
 class PictureBox : Control
 {
 	 property
 	public override void texture(Texture value)
 	{
 		writeln("override");
 		this.m_texture = value;
 	}
 }

 Error: function f340.PictureBox.texture (Texture value) is not 
 callable using argument types ()
Yes, that's normal. If you override one function in a child class, you need to explicitly bring in the other overrides by adding alias texture = Control.texture; // I think you can also use `super.texture` in the class with the new override. That tells it to look up the name from the parent as well. The rationale is here: http://dlang.org/hijack.html It isn't just properties btw, any case of overloads is subject to the same rule.
May 10