翻译请教
|
hqs7636
2008-06-14
allMembers
Takes a single argument, which must evaluate to either a type or an expression of type. An array of string literals is returned, each of which is the name of a member of that type combined with all of the members of the base classes (if the class is a type). No name is repeated. Builtin properties are not included. import std.stdio;
class D
{
this() { }
~this() { }
void foo() { }
int foo(int) { return 0; }
}
void main()
{
auto a = __traits(allMembers, D);
writefln(a);
// [_ctor,_dtor,foo,print,toString,toHash,opCmp,opEquals]
}
import std.stdio;
class D
{
this() { }
~this() { }
void foo() { }
int foo(int) { return 0; }
}
void main()
{
auto a = __traits(allMembers, D);
writefln(a);
// [_ctor,_dtor,foo,print,toString,toHash,opCmp,opEquals]
}
其中这句话怎么翻: each of which is the name of a member of that type combined with all of the members of the base classes 自己尝试的: 其中每个成员的名称是由所有成员的类型的基类构成。 这样翻对吗?5个of,琢磨了好半天有点of迷糊了 Builtin properties 构建属性? 是什么 谢谢 |
|
|
hqs7636
2008-06-14
仔细琢磨了一下代码,有点明白了,大概是:
其中每个名称是由那个类型(及其?)基类(直接继承的类?)的所有成员构成。 |
|
|
RednaxelaFX
2008-06-16
allMembers
Takes a single argument, which must evaluate to either a type or an expression of type. 接受一个参数。该参数必须是一个类型或者一个类型表达式。 An array of string literals is returned, each of which is the name of a member of that type combined with all of the members of the base classes (if the class is a type). 返回一个数组的字符串字面量,其中包括该类型的成员的名字以及该类型的基类的所有成员的名字(如果这个类是一个类型)。 No name is repeated. 名字不会出现重复。 Builtin properties are not included. 不包含内建属性。 类型的内建属性,包括.init,.sizeof,.alignof,.mangleof,.stringof等;所有类型都自动拥有这些属性。而allMembers返回的数组不包括这样的属性成员。 |
|
|
hqs7636
2008-06-16
又遇到一高手了,谢谢,请多指教
|
|
|
Colorful
2008-06-16
如果这个类是一个类型?
难道类不是类型吗? 哈哈。 没必要每个单词都要翻译出来,表达出完整的意思,上下文连贯就OK了。 再比如,如果是个struct,那它哪来的基类? 还是觉得有问题。 我把我翻译的也献出来,供大家商榷。 引用 allMembers只接受一个参数,而该参数必须是某类型或类型表达式。
它返回一个字符串数组,而其中每一项都是该类型的成员名称。如果该类型是个类类型的话,还包括基类的成员名称。 数组中所有名称都不重复[译注:这意味着不能确定是否有函数重载],并且不包含内置属性。[译注:这意味着数组中没有诸如stringof,sizeof等名称] |
|
|
hqs7636
2008-06-16
译得都很好,可能是教&主疏忽
|
|
|
RednaxelaFX
2008-06-16
啊哈哈,Colorful老大好久不见。我确实是没仔细看就回了帖,抱歉抱歉。D里面的class肯定是type(UDT),这个我居然没注意到。
|

