Solved

An easy template quesion

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
C++ dll will not run on machine without VS installed 10 89
White board coding practice 3 92
gdb doesn't stop on breakpoint 2 98
Coding for the first time 9 38
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

808 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