Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Standard C, C++
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 03-29-2005, 01:25 PM   #1 (permalink)
glennandrewcoop
Registered User
 
Join Date: Mar 2005
Posts: 6
glennandrewcoop is on a distinguished road
Problem with multi-dimensional array of pointers

Ok, have a look at the following code, which is throwing up the error:

error C2440: '=' : cannot convert from 'screen::newDim * ' to 'screen::newDim'

in the header file, i have the following:

Code:
typedef customer* newDim;
in the source file, i have the following:

Code:
//Set new row and columns pointer arrays newDim *seatXY = new newDim[x]; for (int i=0; i<x; i++) { seatXY[i] = new newDim[y]; }
x any y have obviously been set at this point, I just basically need a multi-dimensional array holding pointers to references of object customer.

Any help would be greatly appreciated!!
__________________
glennandrewcoop is offline   Reply With Quote
Old 03-29-2005, 03:49 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
This is how you could set up a basic matrix. Observe the very details!
Code:
#include <iostream> using namespace std; //-- int main() { int** Matrix; unsigned nRows(3); unsigned nCols(4); Matrix = new int*[nRows]; if (Matrix != 0) { for(unsigned i = 0; i < nRows; ++i) { Matrix[i] = new int[nCols]; } } //Let's see how we delete them. Watch closely. for(unsigned i = 0; i < nRows; ++i) { delete[] Matrix[i]; } delete[] Matrix; return 0; }
__________________
Valmont is offline   Reply With Quote
Old 03-30-2005, 10:20 AM   #3 (permalink)
glennandrewcoop
Registered User
 
Join Date: Mar 2005
Posts: 6
glennandrewcoop is on a distinguished road
Storing pointer in mulit-dimen array

Thanks for the above, it worked a treat, however, I've just developed my next problem:

I'm trying to allocate a customer object pointer to my int multi-dimensional array (as pointer addresses are int's), though its throwing up the following error:

error C2440: '=' : cannot convert from 'customer *' to 'int'


Here is the code for the function:

Code:
void setSeat(int,int, customer*); void screen::setSeat(int xSeat, int ySeat, customer *cust) { seatsXY[xSeat][ySeat] = cust; }
__________________
glennandrewcoop is offline   Reply With Quote
Old 03-30-2005, 12:21 PM   #4 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
use
PHP Code:
void** Matrix
void can mean anything so you may use

PHP Code:
void screen::setSeat(int xSeatint ySeatcustomer *cust)
{
  
seatsXY[xSeat][ySeat] = (void*)cust;

Or if you're 100% shure + it's called a lot + you want speed increase without "type" checking

PHP Code:
void screen::setSeat(int xSeatint ySeatcustomer *cust)
{
  
seatsXY[xSeat][ySeat] = static_cast<void *>(cust);

__________________
DJMaze is offline   Reply With Quote
Old 03-30-2005, 01:00 PM   #5 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
No void* guys. Not in C++ without a jolly a good reason.

Glenn, just post the code please. Everything.
__________________
Valmont is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Multi Dimensional Array using Vectors. abs Standard C, C++ 16 02-26-2005 04:40 AM
Simple reverse programm silex Standard C, C++ 3 01-22-2005 08:03 AM
Problem Assignment (Urgent help req.) Boltress Standard C, C++ 0 01-12-2005 07:59 AM
working with Multi Dimensional Arrays sde PHP 7 07-11-2004 01:43 PM
sorting multi dimensional arrays sde PHP 4 10-01-2003 05:52 PM


All times are GMT -8. The time now is 09:07 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle