#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Cannot convert type to type* error


    Hi,

    I'm having a problem with my code.
    I have an array: Atom* atoms
    and I'm trying to put a member of the array in another array:
    array[i]=atoms[j];

    and it gives me a compilation error "cannot convert 'Atom' to 'Atom*'

    why is that?

    thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    156
    Rep Power
    34
    Because array[ i ] and atoms[ j ] do not have compatible types.
    According to the information you provided, atoms[ j ] is a value of type Atom;
    according to what I can deduce from the compiler message, array[ i ] is an object of type pointer to Atom.

    The rules of C do not allow you to assign an Atom to a pointer.

    I guess the declaration of array was something like
    Code:
    Atom *array[2000];
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    And I was guessing that atoms was declared as Atom *atoms[42];

    OP needs to reveal to us the actual declarations for atoms and for array and put an end to these guessing games of his.
    Last edited by dwise1_aol; October 3rd, 2012 at 03:24 PM.

IMN logo majestic logo threadwatch logo seochat tools logo