Re: Is this actually valid code?
On 11/7/11, Trass3r wrote: >> Cool stuff, thanks guys. This thing kicks some serious C++ ass. ^^ > > How? You can use using in C++ to do the same. > My bad. I was a bit over-excited there. :p
Re: Is this actually valid code?
Cool stuff, thanks guys. This thing kicks some serious C++ ass. ^^ How? You can use using in C++ to do the same.
Re: Is this actually valid code?
Cool stuff, thanks guys. This thing kicks some serious C++ ass. ^^
Re: Is this actually valid code?
On Sun, 06 Nov 2011 23:10:57 -0500, Andrej Mitrovic wrote: I've had a simple problem where I've only wanted to override a setter from a base class: class Foo { @property void test(int) {} @property int test() { return 1; } } class Bar : Foo { override @property void test(int) {} void bartest() { auto x = test; } // NG } test.d(19): Error: function test.Bar.test (int _param_0) is not callable using argument types () So I thought I'd be clever: class Foo { @property void test(int) {} @property int test() { return 1; } } class Bar : Foo { alias super.test test; override @property void test(int) {} void bartest() { auto x = test; } } And it actually works! Is this a documented feature? http://www.d-programming-language.org/function.html#function-inheritance Look at the third example/description. -Steve
Re: Is this actually valid code?
class Foo { @property void test(int) {} @property int test() { return 1; } } class Bar : Foo { alias super.test test; override @property void test(int) {} void bartest() { auto x = test; } } And it actually works! Is this a documented feature? http://d-programming-language.org/hijack.html
Re: Is this actually valid code?
On Monday, November 07, 2011 05:10:57 Andrej Mitrovic wrote: > I've had a simple problem where I've only wanted to override a setter > from a base class: > > class Foo > { > @property void test(int) {} > @property int test() { return 1; } > } > > class Bar : Foo > { > override @property void test(int) {} > void bartest() { auto x = test; } // NG > } > > test.d(19): Error: function test.Bar.test (int _param_0) is not > callable using argument types () > > So I thought I'd be clever: > > class Foo > { > @property void test(int) {} > @property int test() { return 1; } > } > > class Bar : Foo > { > alias super.test test; > override @property void test(int) {} > void bartest() { auto x = test; } > } > > And it actually works! Is this a documented feature? It has to do with overload sets. I'm pretty sure that it's discussed in the documention. Once you override a base class function in a derived class, the _only_ versions of that function that are in the overload set are the ones in the derived class. If you want the other ones to be in the overload set, you do an alias like you did. I'm a bit surprised that super.test works. I wouldn't have thought that super would work in that context, but apparently it does (I would have expected you to have to do use Foo.test). But yes. This is as expected. - Jonathan M Davis
Is this actually valid code?
I've had a simple problem where I've only wanted to override a setter from a base class: class Foo { @property void test(int) {} @property int test() { return 1; } } class Bar : Foo { override @property void test(int) {} void bartest() { auto x = test; } // NG } test.d(19): Error: function test.Bar.test (int _param_0) is not callable using argument types () So I thought I'd be clever: class Foo { @property void test(int) {} @property int test() { return 1; } } class Bar : Foo { alias super.test test; override @property void test(int) {} void bartest() { auto x = test; } } And it actually works! Is this a documented feature?