Solved

An easy template quesion

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now