GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Mar-2008, 18:02
Meloniasty Meloniasty is offline
New Member
 
Join Date: Mar 2008
Posts: 2
Meloniasty is on a distinguished road

Problem with memory allocation


Hi there, I have some problem with dynamic allocation of two dimensional array. I can manage with base types e.g. int:
CPP / C++ / C Code:
    int**tab;
    tab=new tab* [x];
    for (int i=0; i<x; i++)
    tabl[i]= new int[y];
however when I define my own class:
CPP / C++ / C Code:
     class A{
     //body
}
and try to do as mentioned:
CPP / C++ / C Code:
     A**tab;
     tab=new tab*[x];
     for (int i=0; i<x; i++)
     tab[i]= new A[y];
I receive following error: expected primary-expression before '[' token . I tried to google it, but didnt find proper answer. Could you please enlighten me?
  #2  
Old 01-Mar-2008, 22:51
Blake's Avatar
Blake Blake is offline
Member
 
Join Date: Nov 2005
Posts: 255
Blake is a jewel in the roughBlake is a jewel in the rough

Re: Problem with memory allocation


CPP / C++ / C Code:
tab=new tab*[x];

should be

CPP / C++ / C Code:
tab=new A*[x];
__________________
www.blake-foster.com
  #3  
Old 02-Mar-2008, 00:42
Meloniasty Meloniasty is offline
New Member
 
Join Date: Mar 2008
Posts: 2
Meloniasty is on a distinguished road

Re: Problem with memory allocation


Yeah, made mistake while typing message. Unfortunatety this is not the case ;/ But thanks for reply anyway
EDIT:
Noob me, I found the solotiun. Was writing A[i] rather then tab[i]. That's why writing programs during the night is not a good idea ;/ Sorry for mess.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
Memory Allocation Exceptions in C++ David52 C++ Forum 10 19-Apr-2006 14:13
Memory allocation issue kobi_hikri C++ Forum 6 27-Oct-2005 13:16
Pointer Usage in C++: Beginner to Advanced varunhome C++ Forum 0 19-Aug-2005 10:25
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 19:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:44.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.