| | |
c2440 error??
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 5
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Nov 2007
Posts: 5
Reputation:
Solved Threads: 0
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
•
•
•
•
compiler does not let me put a const int value into the int pointer 3 dim array
"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.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
> *(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
But in order to do that, you need a 3rd level of allocation, namely
> *(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]; •
•
Join Date: Nov 2007
Posts: 5
Reputation:
Solved Threads: 0
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;
......
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?
c++ Syntax (Toggle Plain Text)
int size=0; int ***Flights; int ***F_Rows; //int *F_Columns; void addFlight(const int flightNo, const int numRows, const int numSeatsPerRow){ //increase the size int ***temp1; //F_Rows int ***temp2; temp1=new int**[size]; for(int i=0;i<size;i++){ *(temp1+i)=new int *[numRows]; for(int j=0;j<numRows;j++) *(*(temp1+i)+j)=new int[numSeatsPerRow]; } temp2=new int **[size]; for(int i=0;i<size;i++){ *(temp2+i)=new int *[size]; for(int j=0;j<size;j++) *(*(temp2+i)+j)=new int[size]; } //Flights for(int i=0;i<size;i++){ //make temp1=F_Rows for(int j=0;j<numRows;j++){ for(int k=0;k<numSeatsPerRow;k++) temp1[i][j][k]=F_Rows[i][j][k]; } //make temp2=Flights for(int j=0;j<size;j++){ for(int k=0;k<size;k++) temp2[i][j][k]=Flights[i][j][k]; } } //clear old sized arrays and create same arrays again for(int i=0;i<size;i++){ for(int j=0;j<numRows;j++) delete[] *(*(F_Rows+i)+j); delete[] *(F_Rows+i); } delete[] F_Rows; for(int i=0;i<size;i++){ for(int j=0;j<size;j++) delete[] *(*(Flights+i)+j); delete[] *(Flights+i); } delete[] Flights; size++; F_Rows=new int**[size]; for(int i=0;i<size;i++){ *(F_Rows+i)=new int *[numRows]; for(int j=0;j<numRows;j++) *(*(F_Rows+i)+j)=new int[numSeatsPerRow]; } F_Rows=temp1; for(int i=0;i<size;i++){ for(int j=0;j<numRows;j++) delete[] *(*(temp1+i)+j); delete[] *(temp1+i); //ERROR } 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
•
•
Join Date: Nov 2007
Posts: 5
Reputation:
Solved Threads: 0
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
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
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.
![]() |
Similar Threads
- Difficulty in utilizing functions; C2440 Error (C++)
- VS compiler error??? (C++)
- error help (C++)
- VMWare Unrecoverable Error (*nix Software)
- Error in Wrox Book (Perl)
Other Threads in the C++ Forum
- Previous Thread: how to program usb
- Next Thread: Editing Windows Registry
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






