Solved

An easy template quesion

Posted on 2006-06-10
1
213 Views
Last Modified: 2010-04-01
Hi folks,

I am new to C++ and have a question.

I have a class BST:

template <typename Datatype> class BST
{
...
...
}

BST has three data members:

Node * root (Node is defined within BST as a private class)
int size (default is 0)
queue<Datatype> aQueue (default is NULL)

How shall I write the constructor? (code below is provided, I need to add size and aQueue)

template <typename DataType>
inline BST<DataType>::BST()
: root(0)
{    
}

Thanks
0
Comment
Question by:tiger0516
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
efn earned 50 total points
ID: 16879278
You can initialize size the same way you initialize root.  For example:

: root(0), size(0)

A queue can't be NULL.  It is empty when constructed by default, so if that is acceptable, you don't need to do anything to initialize it.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question