No we should not support enum types derived from strings

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed May 12 14:37:10 UTC 2021


On Wednesday, 12 May 2021 at 02:39:23 UTC, Timon Gehr wrote:
>>          assert(typeid(*this) == typeid(Widget));
>> ...
>
>
> That's a C++ quirk. Not much to do with type theory. In fact, 
> C++ may not be a great example for illustration, as its type 
> system is unsound.

It isn't a quirk. To get dynamic lookup you need to add a virtual 
member.

class A {
public:
     virtual void nothing(){}
     void test(){
         std::cout << typeid(*this).name() << std::endl;
         std::cout << typeid(A).name() << std::endl;
     }
};
class B : public A {
};


void test_typeinfo(){
     B b{};
     b.test();
}



More information about the Digitalmars-d mailing list