c2440 error??

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 5
Reputation: cursedbyfreud is an unknown quantity at this point 
Solved Threads: 0
cursedbyfreud cursedbyfreud is offline Offline
Newbie Poster

c2440 error??

 
0
  #1
Nov 24th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,407
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1468
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: c2440 error??

 
0
  #2
Nov 24th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: cursedbyfreud is an unknown quantity at this point 
Solved Threads: 0
cursedbyfreud cursedbyfreud is offline Offline
Newbie Poster

Re: c2440 error??

 
0
  #3
Nov 24th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: c2440 error??

 
0
  #4
Nov 24th, 2007
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.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: c2440 error??

 
0
  #5
Nov 24th, 2007
> *(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];
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: cursedbyfreud is an unknown quantity at this point 
Solved Threads: 0
cursedbyfreud cursedbyfreud is offline Offline
Newbie Poster

Re: c2440 error??

 
0
  #6
Nov 24th, 2007
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;
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: c2440 error??

 
0
  #7
Nov 24th, 2007
What you've got there, looks like a recipe for disaster.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: cursedbyfreud is an unknown quantity at this point 
Solved Threads: 0
cursedbyfreud cursedbyfreud is offline Offline
Newbie Poster

Re: c2440 error??

 
0
  #8
Nov 24th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,407
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1468
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: c2440 error??

 
0
  #9
Nov 24th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: cursedbyfreud is an unknown quantity at this point 
Solved Threads: 0
cursedbyfreud cursedbyfreud is offline Offline
Newbie Poster

Re: c2440 error??

 
0
  #10
Nov 25th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC