
D language
guang11cheng
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
import
基本导入工作原理:首先,在当前名字空间里搜索名字。如果没有找到,那么就到所有导入的模块里去找。如果在这些导入模块中唯一找到一个,则使用它。如果在多个导入模块里都找到,则报错。默认情况下,导入是private的。即如果 A 导入模块 B,同时 B 又导入模块 C,则 C 的名字是不会被搜索的。一个导入可以特别地声明为public的,即如果在B中导入C的语句形如:public import转载 2012-03-02 22:54:20 · 592 阅读 · 0 评论 -
加锁与解锁,多步事务回滚
// 加锁与解锁class Mutex{}void lock(Mutex m){}void unlock(Mutex m){}void process(){}void mutexDemo(){ Mutex m = new Mutex(); lock(m); // 锁定该互斥量 sc转载 2012-03-04 22:37:30 · 905 阅读 · 0 评论 -
注释
// 单行注释/* 多行注释*//+ 块注释,其中可以嵌套其它类型的注释// 嵌套的单行注释/*嵌套的多行注释*/+/void versionDemo(){ version(none) // 块注释。取消注释用version(all) { writeln("1, hello, worl转载 2012-03-04 16:29:50 · 433 阅读 · 0 评论 -
ddoc
每一个文档都和一个声明(declaration)相关联,原则:1. 如果某单行文档的最左边是空格,它就和后面紧邻的声明关联 2. 多个关联到同一个声明的文档会被连接在一起 3. 没有关联到声明的文档会被忽略 4. 在module声明前的所有文档会被应用到整个模块 5. 如果文档出现在声明的右边,则关联到这个声明 6. 如果文档只是ditto,则使用上一个声明的文档,ditt转载 2012-03-04 17:25:26 · 9431 阅读 · 0 评论 -
模板
// Scoped Templatetemplate Foo(T, U){ class Bar {} // 类 T foo(T t, U u) { return t; } // 函数 T abc; // 变量 alias T* TPtr; // 类型别名}alias Foo!(int, char) TFoo;void de转载 2012-03-05 23:10:09 · 448 阅读 · 0 评论 -
C++ to D
// 构造函数class Foo{ this(int x) {}} class A1 { this() {} int foo() { return 0; }}class B1 : A1{ int a = 7; int b; this() { super(); // 父类的构造函数 b = foo转载 2012-03-07 16:45:50 · 573 阅读 · 0 评论 -
函数嵌套与闭包
// 函数嵌套int demo1(){ int x = 3; int bar(int z) { return x + z; } return bar(2) * bar(3);}// 闭包int delegate(int) add(int lhs){ int foo(in原创 2012-03-11 20:46:29 · 686 阅读 · 0 评论 -
C to D
void demo1(){// 基本类型占用的字节数和取值范围writefln("type\tsizeof\tmin\tmax\tinit");writefln("bool\t%d\t%#x\t%#x\t%#x", bool.sizeof, bool.min, bool.max, bool.init); // bool类型只占1个二进制位writefln("char\t%d\t原创 2012-03-09 20:48:53 · 585 阅读 · 0 评论 -
typeof
// typeof 用来获得一个表达式的类型,但表达式不会被计算bool typeofDemo(int i){ typeof(i) j; // j 的类型是 int typeof(3 + 6.0) x; // x 的类型为 double typeof(1)* p; // p 的类型为指向 int 的指针 int[typeof(p)] a; // a转载 2012-03-04 09:30:15 · 533 阅读 · 0 评论