Re: Virtual functions and inheritance

2015-01-29 Thread Baz via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 04:38:59 UTC, David Monagle wrote: Hi guys, I'm a former C++ developer and really enjoying working with D now. I have a question that I hope some of you may be able to answer. class Parent { @property string typeName() { return typeof(this).stringof; }

Re: Virtual functions and inheritance

2015-01-29 Thread Baz via Digitalmars-d-learn
even more weird: --- module test; import std.conv; interface Meh{ final string typeName() {return to!string(this);} } class Parent : Meh {} class Child : Parent {} void main() { auto p = new Parent; auto c = new Child; assert(p.typeName == __MODULE__ ~ .Parent);

Re: Virtual functions and inheritance

2015-01-29 Thread Tobias Pankrath via Digitalmars-d-learn
This is almost the same code as written initially, let somone explain why the hell this is working: --- module test; import std.conv; class Parent { @property final string typeName() { return to!string(this); } } class Child : Parent { } void main() { auto p = new Parent; auto c

Re: Virtual functions and inheritance

2015-01-27 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 27 Jan 2015 04:38:57 + David Monagle via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: Hi guys, I'm a former C++ developer and really enjoying working with D now. I have a question that I hope some of you may be able to answer. class Parent { @property

Re: Virtual functions and inheritance

2015-01-27 Thread via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 08:19:46 UTC, Daniel Kozák wrote: You can use this T: class Parent { @property string typeName(this T)() { return T.stringof; } } class Child : Parent { } void main() { auto p = new Parent; auto c = new Child; assert(p.typeName ==

Re: Virtual functions and inheritance

2015-01-27 Thread bearophile via Digitalmars-d-learn
Baz: doesn't work. And similarly to the the orginal post: I suggest to read some D documentation first, and program later. Bye, bearophile

Re: Virtual functions and inheritance

2015-01-27 Thread Baz via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 08:19:46 UTC, Daniel Kozák wrote: You can use this T: class Parent { @property string typeName(this T)() { return T.stringof; } } class Child : Parent { } void main() { auto p = new Parent; auto c = new Child; assert(p.typeName ==

Re: Virtual functions and inheritance

2015-01-27 Thread Tobias Pankrath via Digitalmars-d-learn
- class Bar { static T construct(this T, A...)(A a) { return new T(a); } } I think it's a bug that you can use a template this parameter (this T) on a static member function without a direct compilation error. - class Bar { static typeof(this)

Re: Virtual functions and inheritance

2015-01-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 27, 2015 at 04:38:57AM +, David Monagle via Digitalmars-d-learn wrote: Hi guys, I'm a former C++ developer and really enjoying working with D now. I have a question that I hope some of you may be able to answer. class Parent { @property string typeName() { return

Virtual functions and inheritance

2015-01-26 Thread David Monagle via Digitalmars-d-learn
Hi guys, I'm a former C++ developer and really enjoying working with D now. I have a question that I hope some of you may be able to answer. class Parent { @property string typeName() { return typeof(this).stringof; } } class Child : Parent { } void main() { auto p = new Parent;

Re: Virtual functions and inheritance

2015-01-26 Thread David Monagle via Digitalmars-d-learn
I can certainly work with that. Thank you very much! (and for pointing out my typo in the example)