944,033 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3093
  • C++ RSS
Nov 24th, 2007
0

c2440 error??

Expand Post »
Hi, this is my first post here, I searched the forum and google for my error and I found some results but they were not about exactly this error, if there is and if I missed it, I'm so sorry already.
Here is my problem;
const int flightNo;
int ***Flights;
....
Flights=new int **[size];
for(int i=0;i<size;i++){
*(Flights+i)=new int *[size];
..... }
....
for(int i=0;i<size;i++){
*(Flights+i)=flightNo; //this is the error place
...
I just wrote here the main points. Flights is a pointer array-if I learned it right. and the error is

Error 1 error C2440: '=' : cannot convert from 'const int' to 'int **'
I tried to change my array to const int but it still gave this error, I think it is about giving a value to a pointer array. Please can someone explain this error and how to solve it clearly? because I could not understand the relations and the explanations at other results I found under this forum.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cursedbyfreud is offline Offline
5 posts
since Nov 2007
Nov 24th, 2007
0

Re: c2440 error??

Flights is a three-dimensional array because it has three stars. If what you really want is a 2d array then remove one of the asterisks in its declaration.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Nov 24th, 2007
0

Re: c2440 error??

No, sorry I have a bunch of arrays and I gave the wrong error, but you have the idea. I have a three dim. array in purpose, my problem is that Flights[a][b][c]=flightNo, this is the error. compiler does not let me put a const int value into the int pointer 3 dim array. So, does anyone have any idea about this kind of error
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cursedbyfreud is offline Offline
5 posts
since Nov 2007
Nov 24th, 2007
0

Re: c2440 error??

Quote ...
compiler does not let me put a const int value into the int pointer 3 dim array
I don't think there should be any problem with that, i.e. if you have diagonised the bub correctly.
Reputation Points: 193
Solved Threads: 25
Posting Pro
Jishnu is offline Offline
518 posts
since Oct 2006
Nov 24th, 2007
0

Re: c2440 error??

> *(Flights+i)=new int *[size];
> *(Flights+i)=flightNo; //this is the error place
Well these two lines are both accessing the same thing, and only the first one is correct.

> my problem is that Flights[a][b][c]=flightNo, this is the error
So write it like that then
Flights[x][y][z] = flightNo; You're not buying anything with overly complicated pointer expressions involving lots of *'s, +'s and parentheses. It's all the same to the compiler.

But in order to do that, you need a 3rd level of allocation, namely
Flights[x][y] = new int[numZeds];
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Nov 24th, 2007
0

Re: c2440 error??

thank you all, with your help I saw what I did wrong and I have no c2440 error now, however my code is still giving strange warnings;
c++ Syntax (Toggle Plain Text)
  1. int size=0;
  2. int ***Flights;
  3. int ***F_Rows;
  4. //int *F_Columns;
  5. void addFlight(const int flightNo, const int numRows, const int numSeatsPerRow){
  6.  
  7. //increase the size
  8. int ***temp1; //F_Rows
  9. int ***temp2;
  10. temp1=new int**[size];
  11. for(int i=0;i<size;i++){
  12. *(temp1+i)=new int *[numRows];
  13. for(int j=0;j<numRows;j++)
  14. *(*(temp1+i)+j)=new int[numSeatsPerRow];
  15. }
  16. temp2=new int **[size];
  17. for(int i=0;i<size;i++){
  18. *(temp2+i)=new int *[size];
  19. for(int j=0;j<size;j++)
  20. *(*(temp2+i)+j)=new int[size];
  21. }
  22.  
  23. //Flights
  24. for(int i=0;i<size;i++){
  25. //make temp1=F_Rows
  26. for(int j=0;j<numRows;j++){
  27. for(int k=0;k<numSeatsPerRow;k++)
  28. temp1[i][j][k]=F_Rows[i][j][k];
  29. }
  30. //make temp2=Flights
  31. for(int j=0;j<size;j++){
  32. for(int k=0;k<size;k++)
  33. temp2[i][j][k]=Flights[i][j][k];
  34. }
  35. }
  36. //clear old sized arrays and create same arrays again
  37. for(int i=0;i<size;i++){
  38. for(int j=0;j<numRows;j++)
  39. delete[] *(*(F_Rows+i)+j);
  40. delete[] *(F_Rows+i);
  41. }
  42. delete[] F_Rows;
  43. for(int i=0;i<size;i++){
  44. for(int j=0;j<size;j++)
  45. delete[] *(*(Flights+i)+j);
  46. delete[] *(Flights+i);
  47. }
  48. delete[] Flights;
  49. size++;
  50. F_Rows=new int**[size];
  51. for(int i=0;i<size;i++){
  52. *(F_Rows+i)=new int *[numRows];
  53. for(int j=0;j<numRows;j++)
  54. *(*(F_Rows+i)+j)=new int[numSeatsPerRow];
  55. }
  56. F_Rows=temp1;
  57. for(int i=0;i<size;i++){
  58. for(int j=0;j<numRows;j++)
  59. delete[] *(*(temp1+i)+j);
  60. delete[] *(temp1+i); //ERROR
  61. }
  62. delete[] temp1;
......

and the error is
- temp1 0x003a5da0 int * * *
- 0xfdfdfdfd int * *
CXX0030: Error: expression cannot be evaluated
I dont understand this pointers, they are so complicated and I'm dealing with this code for soooooo long I'll loose myself. Please how can I fix it? and why giving this error?
Last edited by Ancient Dragon; Nov 24th, 2007 at 7:18 pm. Reason: add code tags -- please use them
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cursedbyfreud is offline Offline
5 posts
since Nov 2007
Nov 24th, 2007
0

Re: c2440 error??

What you've got there, looks like a recipe for disaster.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Nov 24th, 2007
0

Re: c2440 error??

actually this is a real disaster.you know like everyone that is taking this c++ course, a reservation system for airline company is my homework and I'm trying to solve it, if I can solve the problem I have here, then I can finish all the other parts easily. I don't have to use 3 dim arrays but I could not think anything else. Do you have any other idea to use in here since if you cannot solve the problem here. this is due to 26 nov. and I'm changing this code for 2 weeks and I'm about to cry. I'm about to crush my computer, well in short: can anyone help me pleeeaaassseeeee
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cursedbyfreud is offline Offline
5 posts
since Nov 2007
Nov 24th, 2007
0

Re: c2440 error??

Use std::vector and get rid of all those messy pointers and memory allocations.

A flight consists of X number of rows of N number of seats. You can express that in c++ vector class by
vector< vector<int> > Flight;
Last edited by Ancient Dragon; Nov 24th, 2007 at 7:32 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Nov 25th, 2007
0

Re: c2440 error??

thank you but I do not know vectors, they did not teach it in the class yet, also our instructor expects us to do this homework by pointers. I think I will not pass from this assignment.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cursedbyfreud is offline Offline
5 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: how to program usb
Next Thread in C++ Forum Timeline: Editing Windows Registry





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC