与我之前的问题有点相关
有没有办法从 d 中的函数或方法中获取调用对象?
例子:
class Foo
{
public void bar()
{
auto ci = whoCalledMe();
// ci should be something that points me to baz.qux, _if_ baz.qux made the call
}
}
class Baz
{
void qux()
{
auto foo = new Foo();
foo.bar();
}
}
问题:
- 类似的东西
whoCalledMe
存在吗?如果是这样,它叫什么? - 如果确实存在某些东西,是否可以在编译时(在模板中)使用它,如果是,如何使用?
或者;
- 是否可以在运行时访问调用堆栈?像 php 的
debug_backtrace
?