constructor help!

struct BinaryNode
{
Comparable element;
BinaryNode *left;
BinaryNode *right;

BinaryNode(const comparable & theElement, BinaryNode *lt, BinaryNode *rt)
: element (theElement), left(lt), right(rt) {}
};


Can anyone tell me what this piece of code is?

i know its a structure and BinaryNode is the constructor. I just don't know what the ':' represents and everything after that

'Comparable' is from temple<typename Comparable>
Last edited on
Using the : operator after declaring a function just allows you to easily variables that are members of the class. The constructor could be written like this and have the same effect:
1
2
3
4
5
BinaryNode(const comparable& theElement, BinaryNode *lt, BinaryNode *rt) {
	element = theElement;
	left = lt;
	right = rt;
}


It's just different notation :)
Last edited on
i see! thank you very much!!!!!
Topic archived. No new replies allowed.