另一方面, dchar总是与一个字母相对应,因此与另一个字母类似, D中的经验法则始终使用dchar,除非它用于字符串类型(甚至考虑使用dstring)I'm having trouble instantiating a RedBlackTree container with chars, but it works with ints:import std.stdio;import std.container;void main(){ auto r1 = redBlackTree!(int)(); // works auto r2 = redBlackTree!(char)(); // error instantiating}I'm using DMD32 D Compiler v2.060.Any thoughts? Thanks. 解决方案 you need to use a type that is comparable (i.e. can use the < operator or provide your own comparator as the second template parameterchar (and wchar) is only useful for use in arrays due to one char not necessarily relating to an actual letter in unicode (UTF8 edition) this has other gotcha that will trip up new coders in Ddchar on the other hand will always correspond to a letter and as such is comparable to another letter,rule of thumb in D always use dchar unless it's for a string type (and even then consider using dstring) 这篇关于实例化redBlackTree模板时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-12 08:09