Class inside a Struct?
chardetm via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 30 11:59:58 PST 2015
Hello everyone,
I am currently learning D by coding a project, but I encountered
a problem with one of my structures. I managed to reduce the code
to the minimum:
import std.stdio;
import std.container.rbtree;
struct Container {
private RedBlackTree!int _rbtree = new RedBlackTree!int;
void add (int elt) {
_rbtree.insert(elt);
}
void print () {
if (_rbtree.empty) {
writeln("empty");
} else {
foreach (l; _rbtree) {
write(l, " ");
}
writeln();
}
}
}
int main () {
Container c1, c2;
c1.add(1);
c1.print();
c2.print();
return 0;
}
I don't understand why the output of this program is:
1
1
I expect it to be:
1
empty
I thank you in advance for your help!
More information about the Digitalmars-d-learn
mailing list