dmd2语言的以下代码为什么析构函数被调用了两次import stdstdio;struct Person string name=未分配的名字; int age=0; thisstring nameint age thisname = name; thisage = age; thisstring name
在这段代码中,析构函数被调用了两次的原因是调用了两次destroy函数。destroy函数会自动调用对象的析构函数,因此每次调用destroy函数都会导致析构函数的调用。因此,在这段代码中,析构函数被调用了两次。如果只调用一次destroy函数,析构函数也只会被调用一次。
原文地址: https://www.cveoy.top/t/topic/eZcR 著作权归作者所有。请勿转载和采集!