container class sample on Tango mainpage can not compile
Sam Hu
samhu.samhu at gmail.com
Sun Jan 4 22:52:18 PST 2009
Hi,
The sample of Tango container class,Comparators section:
http://www.dsource.org/projects/tango/wiki/ChapterStorage#Comparators
can not compile.I just don't know why.Please help on this.
//dcomp.d
module dcomp;
import tango.util.collection.TreeBag;
import tango.io.Stdout;
import tango.text.Ascii;
import tango.util.collection.model.Comparator;
void testComparator()
{
auto nameSet=new TreeBag!(char[])(null,new class() Comparator!(char[])
{
int compare(char[] first,char[] second)
{
return Ascii.icompare(first,second);
}
});
nameSet.addIf("Alice");
nameSet.addIf("Bob");
nameSet.addIf("AliCe");
nameSet.addIf("BoB");
nameSet.addIf("Alicf");
nameSet.addIf("BoC");
foreach(str;nameSet)
Stdout.formatln("{}",str);
}
int main(char[][] args)
{
testComparator;
return 0;
}
//end
compile error message:
D:\Laguage\Dex>dsss build dcomp.d
dcomp.d => dcomp
+ c:\bigd\dsss\bin\rebuild.exe -Idsss_imports\ -I. -S.\ -Ic:\bigd\dsss\include\d
-Sc:\bigd\dsss\lib\ -Ic:\bigd\dsss\include\d -Sc:\bigd\dsss\lib -oqdsss_objs\
D dcomp.d -ofdcomp
dcomp.d(11): class dcomp.testComparator.__anonclass6 base type must be class or
interface, not int delegate(char[], char[])
dcomp.d(11): constructor tango.util.collection.TreeBag.TreeBag!(char[]).TreeBag.
this () does not match parameter types (void*,__anonclass6)
dcomp.d(11): class tango.util.collection.TreeBag.TreeBag!(char[]).TreeBag member
this is not accessible
dcomp.d(11): Error: cannot implicitly convert expression ((class __anonclass6 :
Object
{
int compare(char[] first, char[] second)
{
return Ascii.icompare(first,second);
}
void* this;
}
) , new __anonclass6) of type dcomp.testComparator.__anonclass6 to int delegate(
char[], char[])
dcomp.d(11): Error: expected 4 arguments, not 2
Command c:\bigd\dsss\bin\rebuild.exe returned with code 1, aborting.
Error: Command failed, aborting.
More information about the Digitalmars-d-learn
mailing list