hey folks,
i have a template created that holds an array of type T elements. my problem is this ...
i am converting this code from a souped up Array class that takes ints as it's elements to this template Array<T> class that will hold T elements. in the original class, i knew that i was going to be dealing with ints as the elements. so i had a default constructor and a copy constructor that both called a private init method to initialize the array depending on what was passed in.
void IntArray::
init ( const int *data, int sz)
{
assert( (0 <= sz) && (sz <= MAXINT));
d_num_elements = sz;
if ( 0 == d_num_elements ){ // if no elements in array
d_array = NULL; // array points to NULL
}
else{
d_array = new int [d_num_elements];
// allocate memory
// if new returns NULL then no
// more available memory
assert ( NULL != d_array );
}
for (int i=0; i < sz; i++ ){
if ( NULL == data ){
self [i] = 0;
}
else{
self[i] = data[i];
}
}
}
so how do i conver this to make it work for type T? i can't initialize the elements to 0 ...
thanks
crq