LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-31-2005, 04:47 AM   #1
Hady
Member
 
Registered: Nov 2003
Posts: 55

Rep: Reputation: 15
C++: Trouble declaring dynamic array


Hi,

Simple question I guess:

Code:
double *array = new double[variableSize];  // WORKS FINE!
now I want to do:

Code:
double *array[3] = new double[variableSize][3];
I get the error:
cannot convert from 'double (*)[3]' to 'double *[3]'

How do I solve this error?

Many thanks in advance for your much appreciated help.
 
Old 10-31-2005, 05:28 AM   #2
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Re: C++: Trouble declaring dynamic array

Quote:
Originally posted by Hady


Code:
double (*array)[3] = new double[variableSize][3];
 
Old 10-31-2005, 05:33 AM   #3
Hady
Member
 
Registered: Nov 2003
Posts: 55

Original Poster
Rep: Reputation: 15
Merci beaucoup!!
 
Old 10-31-2005, 05:53 AM   #4
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Re: Re: C++: Trouble declaring dynamic array

Code:
double (*array)[3] = new double[variableSize][3];
hmm i didnt know you could do that, i use
Code:
int variableSize, msize;

double **array = new double*[variableSize];
for(int i=0;i<=variableSize-1;i++)array[i] = new double[msize];
thanks for that

Last edited by dmail; 10-31-2005 at 05:54 AM.
 
Old 10-31-2005, 06:04 AM   #5
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
In fact I used the same as dmail
The first is not correctly initialized..
 
Old 10-31-2005, 06:10 AM   #6
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Quote:
Originally posted by Hady
Merci beaucoup!!


Un tres bon cours en francais:

ftp://ftp2.developpez.be/developps/c/PolyCpp.pdf

Last edited by nx5000; 10-31-2005 at 06:15 AM.
 
Old 10-31-2005, 06:15 AM   #7
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
It is correct , I was not sure , I tried
 
Old 11-01-2005, 01:06 AM   #8
Hady
Member
 
Registered: Nov 2003
Posts: 55

Original Poster
Rep: Reputation: 15
merci nx5000 pour le cours C++ en français!

et à bientôt!
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault after declaring a large array. oulevon Programming 6 11-08-2005 02:41 AM
expanding dynamic array niteshadw Programming 6 06-25-2005 11:19 PM
Freeing dynamic array after opengl calls Alf829 Programming 6 05-11-2004 10:49 AM
More dynamic array problems PTBmilo Programming 5 03-14-2003 12:51 AM
dynamic array in class help PTBmilo Programming 6 03-09-2003 02:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration