How can I save a class use the RedBlackTree?

Dsby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 2 20:10:29 PDT 2016


this is the test Code:


import std.container.rbtree;
import std.stdio;

class TClass
{
     int i;
}

void main()
{
     RedBlackTree!(TClass) list = new RedBlackTree!(TClass)();
     auto t = new TClass();
     list.insert(t);
     writeln("The rbtree length is ",list.length());
     list.removeKey(t);
     writeln("The rbtree length is ",list.length());
}

and thisis erro :
/usr/include/dlang/dmd-2.071.0/phobos/std/functional.d-mixin-206(206): Error: mutable method object.Object.opCmp is not callable using a inout object
/usr/include/dlang/dmd-2.071.0/phobos/std/container/rbtree.d(871): Error: template instance std.functional.binaryFun!("a < b", "a", "b").binaryFun!(inout(TClass), TClass) error instantiating
rbtree.d(11):        instantiated from here: 
RedBlackTree!(TClass, "a < b", false)
/usr/include/dlang/dmd-2.071.0/phobos/std/functional.d-mixin-206(206): Error: function object.Object.opCmp (Object o) is not callable using argument types (inout(TClass))
/usr/include/dlang/dmd-2.071.0/phobos/std/container/rbtree.d(873): Error: template instance std.functional.binaryFun!("a < b", "a", "b").binaryFun!(TClass, inout(TClass)) error instantiating
rbtree.d(11):        instantiated from here: 
RedBlackTree!(TClass, "a < b", false)



More information about the Digitalmars-d-learn mailing list