473,796 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<DATATY PE> *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********@yaho o.com
Jul 19 '05 #1
1 2104
"OlgaM" <ol********@yah oo.com> wrote in message
news:37******** *************** ***@posting.goo gle.com...
Hello,

i'm trying to initialize an array.

The class List contains this in its private data members:

ListNode<DATATY PE> *dataItems;

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

dataItems=new DATATYPE[maxNumber];
dataItems = new ListNode<DATATY PE>[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<Lis tNode<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<DATAT YPE> 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
2980
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 happened??? I thought new returns a contiguous block of memory???
8
3273
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 opening to the file. I fail to write a function that allocates memory for a 2d array and returns it to main. I was trying to pass a pointer to the array back to main, but main cannot access the data. The simplified code (no opening of file, but...
7
7023
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
5004
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 not known in the begining. We can assume that it will not exceed 256; class definition:
2
3451
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 can not use the row 0, and the column 0.
1
3410
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 process looks like: Read the NetworkStream to find out size of the data Allocate that amount as a byte array Read the NetworkStream into the byte array Put the byte array into a MemoryStream
13
27442
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
9151
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 inside of a structure. I keep getting segmentation fault errors and I am having trouble understanding why. Here's the parts of the code in question... This is part of the .h file where the struct us defined...
11
3581
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 memory would allocate 256K. The 256K is a fixed memory size. After the compiler has completed compiling header and source code, the execution program might fail to run or crash. The operating system might do not display error message saying,...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.