We are working on a header file for a template class called TreeNode. My class definition is as follows:

#include <iostream>

using namespace std;

template <class T> class BSTree;
class TreeNode<T>;
		friend classBSTree<T>;
		TreeNode( T = T(), TreeNode<T>* = 0, TreeNode<T>* = 0 );
		T data;		//holds data of interest
		TreeNode<T> *linkL;	//pointer to left link
		TreeNode<T> *linkR;  //pointer to right link
	};//end TreeNode

I am unclear on what the argument T = T() means. It was given by the instructor. I understand that it is an argument of type T being initialized. But, don't get what it means to initialize to T()? This leads me to the problem of writing the implementation portion of the header.

This is what I want to write for the function header for the constructor:

TreeNode<T>::TreeNode(T d, TreeNode<T> right, TreeNode<T> left)
data = d;
linkR = right;
linkL = left;

I am really not looking for any code per se. But, would really appreciate a thorough explanation geared toward a novice programmer.

Thanks in Advance.

7 Years
Discussion Span
Last Post by Narue

>But, don't get what it means to initialize to T()?
T() is the default constructor for the type T.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.