can any with C++ experience help me with this simple problem, I can't figure it out.

Sharky Forums


Results 1 to 2 of 2

Thread: can any with C++ experience help me with this simple problem, I can't figure it out.

  1. #1
    Sleeps with the Fishes
    Join Date
    Oct 2000
    Location
    brooklyn, NY USA
    Posts
    367

    can any with C++ experience help me with this simple syntax problem, I can't fig

    hi I can't seem to get this program to comply, it basically try to declare an array of structure using malloc. It ran fine without the use of malloc but when I try malloc I keep getting problem with compling
    ========================================================
    the forum poster seems to have problem displayin the codes properly and shows smilies faces. so I'll put in a link for the codes here. it's very short

    http://www.geniv.com/kin/downloads/struct9a.txt

    ========================================================
    from the "assignaddress" function. on the line that states:
    { khm[i] = (struct address *) malloc(sizeof (struct address));

    on compliation I get the error message:
    Error STRUCT9A.CPP 29: Cannot convert 'address *' to 'address' in function assignaddress(address *)

    anyone can give me a hand with this? thanks in advance
    Last edited by GenIV; 02-24-2003 at 05:54 PM.

  2. #2
    Hammerhead Shark EverlastingGod's Avatar
    Join Date
    Feb 2003
    Location
    MD
    Posts
    1,364
    khm[i] is of type struct address
    malloc is returning a void* which is being cast to a struct address*
    You're assigning this struct address pointer to the struct address...
    You have to rethink what types you want to use.

    BTW if you're using C++ and not plain C, you should use new and delete.
    Stay cool
    and be somebody's fool this year

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •