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 =
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");
assert(c.typ
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;
}
-
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) construct(A
Baz:
doesn't work. And similarly to the the orginal post:
I suggest to read some D documentation first, and program later.
Bye,
bearophile
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 == "Pa
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 == "Pa
V Tue, 27 Jan 2015 04:38:57 +
David Monagle via Digitalmars-d-learn
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 string typeName() {
>
I can certainly work with that. Thank you very much! (and for
pointing out my typo in the example)
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() {
> r
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;
11 matches
Mail list logo