上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 259 下一页
摘要: 原文 题目: template AFields() {int a;} struct A { mixin AFields; } template BFields() {int b;} struct B { mixin BFields; } struct AB { mixin AFields; mixi 阅读全文
posted @ 2022-10-16 17:51 zjh6 阅读(47) 评论(0) 推荐(0)
摘要: import std.stdio; struct Commands { static://置为静 void func001() {writef("1啊");} //假定空,且无参 void func002() {writef("2哈");} } void main(string[] args) { 阅读全文
posted @ 2022-10-16 17:08 zjh6 阅读(15) 评论(0) 推荐(0)
摘要: 原文 如何"提取"并使用闭包中的函数指针? struct S { void function () fp; void foo () { fp = (&bar).funcptr; } void bar () { fp = (&foo).funcptr; } auto fun () // 帮助函数 { 阅读全文
posted @ 2022-10-16 10:17 zjh6 阅读(20) 评论(0) 推荐(0)
摘要: 原文 import std.stdio; class Math { static string noArgs(string[] s) { writeln(s); return ""; } static string withOneArg(string[] s) { writeln(s); retur 阅读全文
posted @ 2022-10-15 22:15 zjh6 阅读(39) 评论(0) 推荐(0)
摘要: 原文 import std.stdio; import std.typecons; alias ScopedBar = typeof(scoped!Bar()); //域bar. class Bar { this() { writeln("Bar"); } ~this() { writeln("~B 阅读全文
posted @ 2022-10-15 21:20 zjh6 阅读(13) 评论(0) 推荐(0)
摘要: 原文 不要在你的opBinary上返回ref.你不能通过ref返回新事物,只能返回成员变量.所以取下ref并替换其为auto.然后编译. auto opBinary(string op, Rhs : meter!(otherValueT), otherValueT) (in Rhs rhs) 代码: 阅读全文
posted @ 2022-10-15 21:09 zjh6 阅读(17) 评论(0) 推荐(0)
摘要: 工作时,创建类(使用自己包装器,或可用Object.factory并用动态调度函数把它转换为某个通用接口),然后使用动态函数.就像: // 注意: 工厂要`模块+类`全名 auto foo = cast(MyDynamic) Object.factory("mymodule.Foo"); asser 阅读全文
posted @ 2022-10-15 20:10 zjh6 阅读(28) 评论(0) 推荐(0)
摘要: 原文 它必须是用户定义的.D中的内置数组要么是静态的,需要在编译时知道,要么是切片成动态数组,可以调整大小. 内置选项: int length = 100; int[] int_array = new int[length]; //== int[] int_array; int_array.leng 阅读全文
posted @ 2022-10-15 18:15 zjh6 阅读(23) 评论(0) 推荐(0)
摘要: 原文 import std.typetuple; alias list = TypeTuple!(AA, AB, AC); 但是,不能在运行时像数组一样索引它;尝试newlist[n]将是编译时错误.相反,创建辅助函数来循环它并返回实例,如下所示: foreach(index, type; list 阅读全文
posted @ 2022-10-15 17:55 zjh6 阅读(28) 评论(0) 推荐(0)
摘要: 原文 我想到了两种可能性.一个是使用UFCS,定义类型作为第一个参数的其他模块中命名函数(它不适合操作符重载),然后可用点语法调用: module myvector; struct vector { float x; float y; } // module myvectormath; import 阅读全文
posted @ 2022-10-15 17:09 zjh6 阅读(16) 评论(0) 推荐(0)
上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 259 下一页