摘要:
原文 module Console; //模块名, import std.string; import core.sys.windows.windows; class Console { public: HANDLE hIn; HANDLE hOut; this(HANDLE hIn, HANDLE 阅读全文
posted @ 2022-09-11 08:29
zjh6
阅读(15)
评论(0)
推荐(0)
摘要:
最开始,以为静态变量好,结果,出现我需要同时使用该类变量,此时,就不能用全局静态变量. 因为,使用它多了,而后面全部改成类对象了. 不用全局静态变量,以前的就要出问题,以前的旧代码就都要改成类对象.使用旧代码时,要注意. 不然,直接使用,会犯大量错误! 使用老代码时,取名时,取新名.不要直接用写串, 阅读全文
posted @ 2022-09-10 18:43
zjh6
阅读(17)
评论(0)
推荐(0)
摘要:
模板可以使用"template this",它们允许传递任何类型. template Test(this ThisType) { pragma(msg, ThisType); } void main() { alias T = Test!int; // Prints "int" } 这也适用于类模板 阅读全文
posted @ 2022-09-10 09:20
zjh6
阅读(18)
评论(0)
推荐(0)
摘要:
原文 我想存储任意类型,要用ubyte数组.但要保存类型信息.用: SumType!(Tuple(int, string, double),Tuple(S, char)) 想出了存储创建时知道确切类型的λ. 因为按序列模板参数(又名可变参数)提供数据,可带带任意数据集. set()为@nogc的. 阅读全文
posted @ 2022-09-09 09:23
zjh6
阅读(29)
评论(0)
推荐(0)
摘要:
原文 因为需要inet_ntop函数,我要包含Ws2tcpip.h头文件. 要复制 const char *inet_ntop(int af, const void *restrict src, char *restrict dst, socklen_t size); 声明为D: extern(C) 阅读全文
posted @ 2022-09-08 10:19
zjh6
阅读(21)
评论(0)
推荐(0)
摘要:
原文 简化示例: lib.c int f(int x) { return x + 1; } app.d import lib; typeof(&__traits(getMember, lib, "f")) fptr; pragma(msg, typeof(fptr)); // extern (C) 阅读全文
posted @ 2022-09-08 09:50
zjh6
阅读(17)
评论(0)
推荐(0)
摘要:
原文 规范说:类不变量是继承的,即,子类要满足基类不变量. import core.exception; class A { int i = 3; invariant { assert(i >= 2); } } class B : A { void setB(int v) { i = v; } in 阅读全文
posted @ 2022-09-08 09:36
zjh6
阅读(11)
评论(0)
推荐(0)
摘要:
原文 import core.runtime; import std.stdio; import std.string; import core.sys.windows.windows; extern(Windows) int WinMain(HINSTANCE hInstance, HINSTAN 阅读全文
posted @ 2022-09-07 20:27
zjh6
阅读(22)
评论(0)
推荐(0)
摘要:
原文 在语言中拥有ImportC有个非常酷的好处.使我们能够动态绑定到C库,而无需手动编写任何绑定代码! 窍门: 第1步:预处理C库头文件,以便可在D中导入它. 第2步:使用D的编译时内省来生成函数指针和相关的加载程序例程. 第3步:后续动作 第4步:利润! static import portau 阅读全文
posted @ 2022-09-07 08:46
zjh6
阅读(31)
评论(0)
推荐(0)
摘要:
原文 void foo(string s) @safe pure nothrow @nogc in (s != "hello", "Invalid " ~ s) { } void main() {} 错误:不能在@nogc的deneme.foo函数中使用~符号. 但是该符号仅在即抛错误时使用,即不应 阅读全文
posted @ 2022-09-06 11:38
zjh6
阅读(28)
评论(0)
推荐(0)
浙公网安备 33010602011771号