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");
}
//---------------------------------------------------------------------------------