473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

allocate memory for a list array with templates

Hello,

i'm trying to initialize an array.

The class List contains this in its private data members:

ListNode<DATATYPE> *dataItems;

In the constructor, i'm trying to allocate space for this array.

dataItems=new DATATYPE[maxNumber];

I'm getting the compiler error
'=' : cannot convert from 'int *' to 'class ListNode<int> *'

what am i doing wrong? Help please.

Olga Mednik
ol********@yahoo.com
Jul 19 '05 #1
1 2082
"OlgaM" <ol********@yahoo.com> wrote in message
news:37**************************@posting.google.c om...
Hello,

i'm trying to initialize an array.

The class List contains this in its private data members:

ListNode<DATATYPE> *dataItems;

In the constructor, i'm trying to allocate space for this array.

dataItems=new DATATYPE[maxNumber];
dataItems = new ListNode<DATATYPE>[maxNumber];

... and if you haven't done so already, don't forget to
create your copy constructor, assignment operator, and
destructor ("rule of three"), to do the 'delete[]'s
and/or reallocations. [1]

I'm getting the compiler error
'=' : cannot convert from 'int *' to 'class ListNode<int> *'

what am i doing wrong? Help please.


[1] You can preempt many headaches and bugs if you
use a container (e.g. a std::vector), instad of an array.
All the memory management would be done for you.

std::vector<ListNode<DATATYPE> > dataItems;

And unless you're making your own linked list
for learning purposes, you might consider using
the standard library's list class (which also
manages its own memory):

std::list<DATATYPE> dataItems;

HTH,
-Mike
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: bluekite2000 | last post by:
I was able to allocate a single array having 2.6GB (ie. w/ 700200000 elements of type float) yet when I did a cpuinfo on my computer, it showed a cache size of 256KB and 1GB of memory. What...
8
by: M. Moennigmann | last post by:
Dear all: I would like to write a function that opens a file, reads and stores data into an 2d array, and passes that array back to the caller (=main). The size of the array is not known before...
7
by: bijax | last post by:
hi, i am new to multidimensional array of c programming .pls help me to solve out this how to allocate memory for mutidimensional array? i.e a ;
4
by: marora | last post by:
I have created class definition which contains a charater pointer as one of it's data memeber. The objective is to read some data from a file, and assign it to a data member; Size of data is...
2
by: xhunga | last post by:
I have try a new version of my work. I have put the sizes of the matrix into the matrix. A = number of rows A = number of columns The first element of the matrix is A instead of A. You...
1
by: trevor.farchild | last post by:
Hi, long time reader, first time poster I have an application that will be doing this 5 times a second: Get a bunch of data from a NetworkStream and convert it into a Bitmap Therefore, the...
13
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
17
by: dtschoepe | last post by:
Hi, I have a homework project I am working on, so be forwarned, I'm new to C programming. But anyway, having some trouble with a memory allocation issue related to a char * that is a variable...
11
by: Bryan Parkoff | last post by:
I want to know how much static memory is limited before execution program starts. I would write a large array. The large array has 65,536 elements. The data size is double word. The static...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.