February 02, 2016 How do you do a typeid(obj) to get the most derived class that it is, or string? | ||||
---|---|---|---|---|
| ||||
class A { } class B : A { } class C : B { } auto b = new B(); typeid(b) == "B" ? Thanks. |
February 01, 2016 Re: How do you do a typeid(obj) to get the most derived class that it is, or string? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Enjoys Math | On 02/01/2016 10:20 PM, Enjoys Math wrote:
>
> class A {
>
> }
>
> class B : A {
>
> }
>
> class C : B {
>
> }
>
> auto b = new B();
>
> typeid(b) == "B"
>
> ?
>
> Thanks.
class A {
}
class B : A {
}
class C : B {
}
void main() {
auto b = new B();
assert(typeid(b) == typeid(B));
// Or, if you have the type without an object (e.g. in templated code)
assert(typeid(typeof(b)) == typeid(B));
}
Ali
|
Copyright © 1999-2021 by the D Language Foundation