Thread: Pointer confusion

  1. #1
    Registered User
    Join Date
    Mar 2010

    Pointer confusion

    Say I have a class Pawn with a constructor Pawn(enum colors {white,black} Color).

    Now, somewhere else in my program, I have to make a 2D array of pointers pointing to pawns.

    First of all, how can I create a normal 1D array with 5 elements? Pawn myPawn(black) works, but how does Pawn myPawnArray[5] work? Is there a way around f.e. Pawn array[2] = {Pawn(Pawn::white), Pawn(Pawn::black)}; (I've thought about pointers but how is this done?)

    Second question, how can you again make an array of pointer variables? In this example, an array with pointers to pawns? I need to refresh this again because I haven't worked with it for about a year... I'm pretty sure it's done by **array or *array[], but I fail to see why *array[] works again.

    After that I should manage to figure it for *array[][] which is a 2D array of pointers pointing to pawns...


  2. #2
    Registered User
    Join Date
    Aug 2010
    Post some code. Consider using a vector of pointers, that is vector<Pawn*>.

    An array of pointers:
    Pawn* arr[5];

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    Consider avoiding pointers. A simple 2D array can be made with vectors:
    std::vector<std::vector<Pawn>> PawnArray;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer + struct w/arrays confusion
    By Viper187 in forum C Programming
    Replies: 1
    Last Post: 07-23-2009, 09:37 AM
  2. pointer confusion
    By rohit_second in forum C Programming
    Replies: 1
    Last Post: 10-20-2008, 04:25 AM
  3. Question About Pointer To Pointer
    By BlitzPackage in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 10:19 PM
  4. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  5. Pointer confusion...
    By fkheng in forum C Programming
    Replies: 13
    Last Post: 06-23-2003, 10:18 PM