www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is this a bug?

reply freeagle <freeagle inmail.sk> writes:
I have a class BaseWindow
{
Dimension2D size()
	{
		return _size;
	}

abstract void size(Dimension2D size);
}

and derived class Win32Window : BaseWindow
{
void size(Dimension2D size)
{
	_size.set(size);
}
}

lets say i have a reference to class Win32Window. When i try to call 
method _window.size(), compiler complains it doesn't match arguments 
size(Dimension2D). Until i specify is to 
(cast(BaseWindow)_window).size(). Why??
Jul 08 2006
parent reply Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
freeagle wrote:
 I have a class BaseWindow
 {
 Dimension2D size()
     {
         return _size;
     }
 
 abstract void size(Dimension2D size);
 }
 
 and derived class Win32Window : BaseWindow
 {
 void size(Dimension2D size)
 {
     _size.set(size);
 }
 }
 
 lets say i have a reference to class Win32Window. When i try to call 
 method _window.size(), compiler complains it doesn't match arguments 
 size(Dimension2D). Until i specify is to 
 (cast(BaseWindow)_window).size(). Why??
I don't remember the exact reason, but try aliasing 'size' from the BaseWindow's scope, like: class Win32Window : BaseWindow { void size(Dimension2D size) { ..... } alias super.size size; // iirc } -- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
Jul 08 2006
parent reply freeagle <freeagle inmail.sk> writes:
Tom S wrote:
 freeagle wrote:
 I have a class BaseWindow
 {
 Dimension2D size()
     {
         return _size;
     }

 abstract void size(Dimension2D size);
 }

 and derived class Win32Window : BaseWindow
 {
 void size(Dimension2D size)
 {
     _size.set(size);
 }
 }

 lets say i have a reference to class Win32Window. When i try to call 
 method _window.size(), compiler complains it doesn't match arguments 
 size(Dimension2D). Until i specify is to 
 (cast(BaseWindow)_window).size(). Why??
I don't remember the exact reason, but try aliasing 'size' from the BaseWindow's scope, like: class Win32Window : BaseWindow { void size(Dimension2D size) { ..... } alias super.size size; // iirc }
the problem is not that i have to type a bit more to actually call the method, i just don't understand why its not part of Win32Window interface, when Win32Window class is publicly derived from BaseWindow defining public method Dimension2D size();
Jul 08 2006
next sibling parent reply Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
freeagle wrote:
 the problem is not that i have to type a bit more to actually call the 
 method, i just don't understand why its not part of Win32Window 
 interface, when Win32Window class is publicly derived from BaseWindow 
 defining public method Dimension2D size();
That may be because of the symbol resolution method that is currently being attacked in various posts. In that one example of yours, the compiler figures out that you want a 'size' function of the Win32Window, it checks it and cant see the right version. It doesnt check the base class because of how the method resolution works. Weird, yeah :P -- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
Jul 08 2006
parent reply freeagle <freeagle inmail.sk> writes:
Tom S wrote:
 freeagle wrote:
 the problem is not that i have to type a bit more to actually call the 
 method, i just don't understand why its not part of Win32Window 
 interface, when Win32Window class is publicly derived from BaseWindow 
 defining public method Dimension2D size();
That may be because of the symbol resolution method that is currently being attacked in various posts. In that one example of yours, the compiler figures out that you want a 'size' function of the Win32Window, it checks it and cant see the right version. It doesnt check the base class because of how the method resolution works. Weird, yeah :P
well yeah, this way, you have to show whole inheritance tree to the user of the lib so he can use it. I think this damages encapsulation. I dont want the user to know there is a BaseWindow class, i want him to be happy just with a knowledge of Win32Window class.
Jul 08 2006
parent freeagle <freeagle inmail.sk> writes:
freeagle wrote:
 Tom S wrote:
 freeagle wrote:
 the problem is not that i have to type a bit more to actually call 
 the method, i just don't understand why its not part of Win32Window 
 interface, when Win32Window class is publicly derived from BaseWindow 
 defining public method Dimension2D size();
That may be because of the symbol resolution method that is currently being attacked in various posts. In that one example of yours, the compiler figures out that you want a 'size' function of the Win32Window, it checks it and cant see the right version. It doesnt check the base class because of how the method resolution works. Weird, yeah :P
well yeah, this way, you have to show whole inheritance tree to the user of the lib so he can use it. I think this damages encapsulation. I dont want the user to know there is a BaseWindow class, i want him to be happy just with a knowledge of Win32Window class.
ok, you dont, im taking back my last statements ;) thanks guys for the help
Jul 09 2006
prev sibling parent Bruno Medeiros <brunodomedeirosATgmail SPAM.com> writes:
freeagle wrote:
 Tom S wrote:
 freeagle wrote:
 I have a class BaseWindow
 {
 Dimension2D size()
     {
         return _size;
     }

 abstract void size(Dimension2D size);
 }

 and derived class Win32Window : BaseWindow
 {
 void size(Dimension2D size)
 {
     _size.set(size);
 }
 }

 lets say i have a reference to class Win32Window. When i try to call 
 method _window.size(), compiler complains it doesn't match arguments 
 size(Dimension2D). Until i specify is to 
 (cast(BaseWindow)_window).size(). Why??
I don't remember the exact reason, but try aliasing 'size' from the BaseWindow's scope, like: class Win32Window : BaseWindow { void size(Dimension2D size) { ..... } alias super.size size; // iirc }
the problem is not that i have to type a bit more to actually call the method, i just don't understand why its not part of Win32Window interface, when Win32Window class is publicly derived from BaseWindow defining public method Dimension2D size();
The relevant doc specification, is on http://www.digitalmars.com/d/function.html , Function Inheritance and Overriding: "However, when doing overload resolution, the functions in the base class are not considered: [...] To consider the base class's functions in the overload resolution process, use an AliasDeclaration:" I'm also not sure if this is the ideal behavior. -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Jul 09 2006