Solved

An easy template quesion

Posted on 2006-06-10
1
214 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  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 …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

690 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