您的位置:首页 > 编程语言

D语言游戏编程(3):D语言基础之Attributes

2007-01-08 18:19 381 查看
下面是D语言文档Attributes一节讲述的主要内容,还是看代码吧!


import std.stdio;




void main()




...{


tryAttributes();


}




//-- begin of Attributes ----------------------------------------------------------


//attribute语法上都支持后面跟一个大括号的形式


const




...{


int A_CONST_INT = 100;


int B_CONST_INT = 100;


}


const int C_CONST_INT = 100;




abstract class MyBase




...{


this()




...{


writefln("MyBase.ctor");


}


~this()




...{


writefln("MyBase.dtor");


}




void showMe()




...{


writefln("MyBase.showMe");


}


}




class MyClass : MyBase




...{


this()




...{


writefln("MyClass.ctor()");


super(); //可以决定父类构造函数调用的位置,如果没有这行则先调用


}




~this()




...{


writefln("MyClass.dtor()");


}




override void showMe()




...{


writefln("MyClass.showMe");


}




}




void tryAttributes()




...{


//attribute是声明的修饰符








//


//虚基类不能创建实例


//MyBase mb = new MyBase;//Error: cannot create instance of abstract class MyBase




MyClass mc = new MyClass;




writefln("---- enter scope");




...{


//scope -- 离开作用域之后自动析构


scope MyClass mm = new MyClass;




//override函数调用


MyClass tt = mm;


tt.showMe();


}


writefln("---- leave scope");


}




//---------------------------------------------------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: