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 **;
for(int i=0;i<size;i++){
*(Flights+i)=new int *;
.....       }
....
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.

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.

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][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

I don't think there should be any problem with that, i.e. if you have diagonised the bub correctly.

> *(Flights+i)=new int *;
> *(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][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];

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?

Member Avatar for iamthwee

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

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:

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;

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.