[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RE: C++ question



It is my understandng that in order for C++ to "delete" a dynamically-allocated
object, that object need to have been created via "new".

That said, I'd like to see the code where you do the allocation.

Also, you may need to type-cast the void pointer.  The new compiler version
may be more picky about that sort of thing (though if that's the case it should
be a warning, not an error).

The comp.lang.c++ people will peobably be more helpful though.

If you do get a response, could you forward me a copy?  thanks.

Bryan


On 15-Feb-2000 Shao Zhang wrote:
> Hi, 
>       I have posted this to comp.lang.c++, but hope someone here can
>       help me as well. Thanks.
> 
> =====================
>         I have a c++ program that compiles fine with
>         earlier version of g++, but it no longer compiles with
>         the newsest release 2.95.2.
> 
>         Here is the relevant bit of code:
> 
>         typedef struct List
>         {
>                 void            **hd;   /* first item */
>                 void            **cr;   /* current item */
>                 void            **tl;   /* last item */
>                 void            **mx;   /* max item before growing is
> required */
>                 int             grow_size;
>         } List;
> 
>         Some macros defined:
> 
>         #define fast_list_first(l)      ((l && l->hd)? *(l->cr = l->hd) : 0)
>         #define fast_list_last(l)       ((l && l->hd)? *(l->cr = l->tl) : 0)
> 
>         And a Function like this:
>         void lfree(List *l)
>         {
>                 void *item;
>                 for (item=fast_list_first(l); item != NULL;
> item=fast_list_last(l))
>###->>>>                delete item;
>         }
> 
> 
>         When compiled with g++(2.95.2), it failed with this:
>         [line 55 is the line marked with arrows above]
>         % g++ -g -c misc.c
>         misc.c: In function `void lfree(List *)':
>         misc.c:55: warning: `void *' is not a pointer-to-object type
> 
>         It gives me the warning message, but no .o file is created, and
>         if I put it in a makefile, it results:
>         % make misc.o
>         g++ -g -c misc.c
>         misc.c: In function `void lfree(List *)':
>         misc.c:55: warning: `void *' is not a pointer-to-object type
>         make: *** [misc.o] Error 1
> 
> 
>         Thanks for any help in advance.
> 
> Shao.
> 
> 
> -- 
> ____________________________________________________________________________
> Shao Zhang - Running Debian 2.1  ___ _               _____
> Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
> University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
> Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
> Email: shao@cia.com.au                                                  |___/
> _____________________________________________________________________________
> 
> 
> -- 
> Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org <
> /dev/null


Reply to: