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
Old 04-11-2005, 06:47 AM   #1 (permalink)
glennandrewcoop
Registered User
 
Join Date: Mar 2005
Posts: 6
glennandrewcoop is on a distinguished road
Help required with pointers

Can someone have a look at the following code:

PHP Code:
void screen::setMultiArray(const int x, const int y)
{
  
seatsXY = new customer***[4];

  for (
int i=0;i<5;i++)
  {
    
seatsXY[i] = new customer**[x];

    for (
int j=0j<xj++)
      {
        
seatsXY[i][j] = new customer*[y];
      }
  }


its a small function to set up a dynamic three-dimensional array of pointers of type customer.

Later in the program, I need to test each pointer in the array, one by one, to see if an actual reference has been set to that pointer. Does anybody know how to do this?

Thanks for your help.
glennandrewcoop is offline   Reply With Quote
Old 04-11-2005, 10:58 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
If your 3d array contains pointers, then set them all to "0". Then a simple test will do:
Code:
if(seatsXY[i][j][k] != 0)
{
   //pointer not set.
}
Just a tip:
If you're confident with pointers then there is no real excercise in this sort of a 3d array: it is not *that* fast. You could easely use nested std::vector(s) or std::valarray(s).
__________________

Last edited by Valmont; 04-11-2005 at 11:20 AM.
Valmont is offline   Reply With Quote
Reply

Bookmarks

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

BB 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
Problem with multi-dimensional array of pointers glennandrewcoop Standard C, C++ 4 03-30-2005 02:00 PM
far or near iwanttolearnc Standard C, C++ 2 06-15-2004 10:28 PM
A day late and pointers short saline Standard C, C++ 2 10-04-2003 11:33 AM
Pointers w00t Standard C, C++ 14 03-02-2003 01:15 PM
pointers .. sde Standard C, C++ 2 06-24-2002 01:54 PM


All times are GMT -8. The time now is 09:08 AM.


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





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting