Thread: Arrays of Pointers

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    17

    Arrays of Pointers

    Say I want an Array of Pointers to Classes. This is dynamic btw, so the size isnt always set.

    Shouldn't i do this???

    Code:
    CClass** array;
    
    array = new int[someNumber];
    
    for (i=0; i < someNumber; i++)
    {
         array[i] = new CClass;
    }
    Well im not completely certain... The second line of code works (well it doesnt seem to) because integers and pointers are both just 32bits in memory.

    The error Im getting is on that second line and goes something like this...

    error C2440: '=' : cannot convert from 'int *' to 'class CClass ** '
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    Thanks for any help, im sure this is just as simple as adding a * somewhere but, well i cant figure out where...

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    17
    ok, well just solved my problem
    for anyone who cares it should go something like this
    Code:
    array = new CClass*[somenumber];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with returning arrays using pointers
    By cuba06 in forum C Programming
    Replies: 9
    Last Post: 11-23-2007, 10:40 AM
  2. Array of Pointers to Arrays
    By Biozero in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 02:31 PM
  3. Pointers and multi dimensional arrays
    By andrea72 in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2007, 04:49 PM
  4. pointers and arrays..
    By ahming in forum C Programming
    Replies: 1
    Last Post: 04-24-2004, 03:12 AM
  5. Stack functions as arrays instead of node pointers
    By sballew in forum C Programming
    Replies: 8
    Last Post: 12-04-2001, 11:13 AM