当前位置:网站首页>D constructor problem
D constructor problem
2022-07-02 18:02:00 【fqbqrr】
/// module g.d
class world
{
atlasHandler atlas;
void do()
{
atlas = new AtlasHanlder();
elf e = new elf(atlas);
}
}
/// module 'objects.d'
class atlasHandler{
}
class elf
{
this(atlasHandler atlas)
{
assert(atlas !is null); // normal
assert(g.world.atlas !is null); // collapse
writefln("atlas [%p] vs g.world.atlas [%s]", atlas, g.world.atlas);
// read g.world.atlas when , collapse .
}
}
world
by null
Because it is not constructed success
. There are Segment error
.
It's also like you used to Segment error
The source of the . you are here Constructors
There is Circular reference
. namely , You are constructing Global world instance
, It is constructed again visit
The constructor has not been completed The whole world
Refer to the elf
example , therefore Global world reference
It's still empty .
If you're building The world
, And you need to access it , Can be :
1, Use idle Destructor
Incipient world , And then call... On it setup
Methods do the work of the constructor ;
2, from The world
Passed in constructor this
Give it to all who need it Constructors
.
similar :
import std.stdio : writeln;
class Foo {
Bar b;
this() {
b = new Bar; }
void sayMyName() {
writeln(" ha-ha ."); }
}
class Bar {
this() {
f.sayMyName(); }
}
Foo f;
void main()
{
f = new Foo;
}
Module independent . It is quote
Oneself .
stay Constructors
Return to the former , Construct instance quote
by null
. And in modular , Function field, etc
It doesn't matter . If Not constructed
success ( Segment error , Abnormal throwing , Conclude failure, etc ), be quote
Always be null
. quote
No example
. It is an example The pointer
. Already called Constructors
when example
It works , because this
References must be valid . Consider ordinary function calls :
T newT() {
T t = allocT();
t.construct(t);
return t;
}
T g = newT();
If t.construct
Throw or collapse , It won't be implemented return t
, Nor will it be incipient g
.
边栏推荐
- Yingguang single chip microcomputer (MCU popular science)
- 松翰SN8P2511 SOP8单片机 可代烧录 提供单片机方案开发 单片机解密
- ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
- 辉芒微IO单片机FT60F11F-MRB
- PMS132B单片机TWS数码管蓝牙充电仓方案开发
- The price is only 40 yuan. Pico development board of raspberry pie is added with WiFi module, and it is out of stock as soon as it comes into the market
- 应广PMC131 SOP16 16pin八位单片机
- 读写 XML/JSON/INI 和 UBJSON 等格式的数据文件的统一接口
- Bluetooth technology | new working mode of wearable devices of the Internet of things, and Bluetooth ble helps the new working mode
- Virtual lab basic experiment tutorial -7 Polarization (2)
猜你喜欢
Pfc232-sop8/14/16 should be wide-ranging and can be tape programmed with burning program
[how is the network connected] Chapter 4 explores access networks and network operators
台湾飞凌FM8PB513B单片机提供单片机方案开发 产品设计
515. 在每个树行中找最大值
Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
[games101] operation 4 B é zier curve
Chapter 15 string localization and message Dictionary (1)
体验一下阿里云文字识别OCR
深入理解ThreadLocal
随机推荐
Troubleshooting ideas that can solve 80% of faults
Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
怎么可以省去大量的switch语句,省去switch语句
PHP gets the number of days, hours, minutes and seconds between the two timestamps
Easyai notes - deep learning
【Zuul】com.netflix.zuul.exception.ZuulException: Hystrix Readed time out
Ora-19838 -- restore control files to the standby database
基数排序的简单理解
[how is the network connected] Chapter 4 explores access networks and network operators
自定义一个loading指令
EdgeNeXt打出了一套混合拳:集CNN与Transformer于一体的轻量级架构
Pms132b single chip microcomputer TWS digital tube Bluetooth charging chamber program development
MySQL安装与配置
Does pytorch support 32 bits?
Daily question - inverted string
What is the experience of maintaining Wanxing open source vector database
vimium映射鍵
Aloam code reading and summary
Yilong em78p153k dip14 MCU
售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销