Is there a generic type such as void* or C#'s object?
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Feb 6 02:18:29 UTC 2021
On Sat, Feb 06, 2021 at 02:01:28AM +0000, Jack via Digitalmars-d-learn wrote:
> in C/C++ you have void* and C#'s object, to create a variable to hold
> a genetic type. So in C# you can do:
>
> class A {
> object foo;
> }
>
> and
>
> var a = new A();
> a.foo = any class...;
>
> does D have something like this or template parameters are used
> instead of?
D has void*.
But if you have a class, it's probably better to use the universal base
class Object, which is more type-safe.
Alternatively, check out std.variant, which provides true dynamic
typing as a tagged union.
T
--
"You know, maybe we don't *need* enemies." "Yeah, best friends are about all I can take." -- Calvin & Hobbes
More information about the Digitalmars-d-learn
mailing list