On Sun, Jan 01, 2023 at 12:35:40AM +0000, Paul via Digitalmars-d-learn wrote:
> Hello.  Thanks for any assistance.
> 
> Can I acquire the address of a class object, not a class variable
> (i.e. the instantiations of the class) but the object definition
> itself?
> 
> ```d
> class MyClass {char c}
> ...
> MyClass MyClassVar;
> 
> writeln(&MyClassVar); // this compiles
> writeln(&MyClass);    // this does not
> ```

What's your purpose in doing this?  Maybe if you explain what you're
trying to accomplish, we can better understand how to help you.

The class definition does not have an address, because it's an abstract
definition that only exists during compilation.  At runtime the class
definition isn't stored anywhere. So it isn't possible to take its
address.

There is, however, typeid(MyClass), which is a runtime structure that
gives you some amount of information about the class. But the use of
typeid is discouraged due to some inherent issues with its design.


T

-- 
Designer clothes: how to cover less by paying more.

Reply via email to