954,219 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

c2440 error??

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

cursedbyfreud
Newbie Poster
5 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

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

cursedbyfreud
Newbie Poster
5 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 
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.

Jishnu
Posting Pro
518 posts since Oct 2006
Reputation Points: 193
Solved Threads: 25
 

> *(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];

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

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;

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?

cursedbyfreud
Newbie Poster
5 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

What you've got there, looks like a recipe for disaster.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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 :icon_cry:

cursedbyfreud
Newbie Poster
5 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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;

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

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.

cursedbyfreud
Newbie Poster
5 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You