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");
}
//---------------------------------------------------------------------------------
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");
}
//---------------------------------------------------------------------------------
相关文章推荐
- D语言游戏编程(5):D语言基础之Pragmas,Expressions,Statements
- D语言游戏编程(9):D语言基础之interface和enum
- D语言游戏编程(10):D语言基础之函数和操作符重载
- D语言游戏编程(11):D语言基础之模板和混入(mixin)技术
- D语言游戏编程(6):D语言基础之Arrays
- D语言游戏编程(2):D语言基础之Declarations,Types,Properties
- D语言游戏编程(7):D语言基础之struct
- 语言基础:C#输入输出与数据类型及其转换
- C语言基础代码
- C语言基础知识备忘
- java软件工程师培训学习日记------java语言核心基础之面向对象编程
- PLSQL语言基础
- 《.net编程先锋C#》第二章 理论基础-公用语言 运行环境
- 黑马程序员——OC语言基础---id类型及应用场景
- 3. SQL语言基础
- java软件工程师培训学习日记------java语言核心基础之数组
- C语言基础总结1
- JavaScript语言基础---(六)匿名函数
- Java语言基础——java 变量
- 3.06课·········C#语言基础