M
Mike
Hey!
I've started to use templates for storing arrays of doubles.
The template itself will then be passed on to a linked-list.
My problem is that Im not 100% familiar with how templates
are handeled. What I want to do is to allocate it on the heap
then pass it to my linked-list as a part of another object.
(I dont want it to go out of scope!!!)
I tried to following example without success!
....
#include "theArray.h"
#include <stdio.h>
int
main(int argc, char* argv[])
{
// typedef
typedef theArray<double*> TheArray;
// fill
int num = 20;
// vars
TheArray *array
= new TheArray(num);
for (int i=0; i<num; i++)
{
double *value;
double *ptr;
double *data
= new double[4];
ptr = data;
*array = ptr; <-- SEGMENTATION_FAULT!
}
printf("Exit ...\n");
return 0;
}
....
Could somebodu point in the right direction on how templates are handeled
on the heap and how to pass them on as a pointer another object.
Examples or links are more than welcome!
Thanks!
// Mike
I've started to use templates for storing arrays of doubles.
The template itself will then be passed on to a linked-list.
My problem is that Im not 100% familiar with how templates
are handeled. What I want to do is to allocate it on the heap
then pass it to my linked-list as a part of another object.
(I dont want it to go out of scope!!!)
I tried to following example without success!
....
#include "theArray.h"
#include <stdio.h>
int
main(int argc, char* argv[])
{
// typedef
typedef theArray<double*> TheArray;
// fill
int num = 20;
// vars
TheArray *array
= new TheArray(num);
for (int i=0; i<num; i++)
{
double *value;
double *ptr;
double *data
= new double[4];
ptr = data;
*array = ptr; <-- SEGMENTATION_FAULT!
}
printf("Exit ...\n");
return 0;
}
....
Could somebodu point in the right direction on how templates are handeled
on the heap and how to pass them on as a pointer another object.
Examples or links are more than welcome!
Thanks!
// Mike