Parameterized types and return values in D why does this not work?
I've recently gotten into D, and was trying to build a binary tree
implementation as a way of testing what I've learned by reading about it.
Now, I started by declaring it as follows:
class BinaryTree(T)
I figured this would allow me to parametrize some of the stuff the class
holds. More specifically:
T _data;
BinaryTree!(T) _left;
BinaryTree!(T) _right;
Now, I then tried writing this:
BinaryTree!(T) findNearest (BinaryTree(T) x, T key) {
if (x.hasNoChildren || x.data == key) {
return x; //found it
}
else {
auto compare = x.data;
if (compare > key) {
return find (x.left, key);
}
else {
return find (x.right, key);
}
}
}
After this, the compiler loudly complained about my function not having a
return type. What am I doing wrong here? If it helps to explain, I come
from a Java background, and I'm using the dmd compiler inside of Xamarin
Studio.
No comments:
Post a Comment