digitalmars.D.learn - How to get the type of a derived class in a method of its base class?
- Max Samukha (11/11) Feb 18 2017 class A {
- aberba (4/10) Feb 19 2017 is B not supposed to inherit from A?
- Mike Parker (4/15) Feb 19 2017 I believe template this parameters[1] are what you're looking for
- biozic (13/24) Feb 19 2017 Not at compile time:
class A {
this(T = this)() {
static assert(is(T == B));
}
}
class B {
}
auto b = new B;
Here, T becomes A, which may be reasonable but is completely
useless. Is there a way to obtain the type of the class (or class
instance reference) the method is called on?
Feb 18 2017
On Sunday, 19 February 2017 at 07:52:13 UTC, Max Samukha wrote:
class B {
}
auto b = new B;
Here, T becomes A, which may be reasonable but is completely
useless. Is there a way to obtain the type of the class (or
class instance reference) the method is called on?
is B not supposed to inherit from A?
like
class B: A {}
Feb 19 2017
On Sunday, 19 February 2017 at 07:52:13 UTC, Max Samukha wrote:
class A {
this(T = this)() {
static assert(is(T == B));
}
}
class B {
}
auto b = new B;
Here, T becomes A, which may be reasonable but is completely
useless. Is there a way to obtain the type of the class (or
class instance reference) the method is called on?
I believe template this parameters[1] are what you're looking for
here.
https://dlang.org/spec/template.html#template_this_parameter
Feb 19 2017
On Sunday, 19 February 2017 at 07:52:13 UTC, Max Samukha wrote:
class A {
this(T = this)() {
static assert(is(T == B));
}
}
class B {
}
auto b = new B;
Here, T becomes A, which may be reasonable but is completely
useless. Is there a way to obtain the type of the class (or
class instance reference) the method is called on?
Not at compile time:
class A
{
this()
{
assert(typeid(this) == typeid(B));
}
}
class B : A
{
}
auto b = new B;
Feb 19 2017









aberba <karabutaworld gmail.com> 