Problem with "delete" and what about "friend" classes & functions?

John Kiro johnkirollos at yahoo.com
Sat Jan 6 02:12:21 PST 2007


== Quote from Johan Granberg (lijat.meREM at OVE.gmail.com)'s article
> John Kiro wrote:
> > Hello
> >
> > I have a problem with this statement:
> >
> >   delete pDoc.getFile();
> >
> > It generates this error:
> >
> > "Error: ((cast(CDoc)(pDoc)).getFile)() is not an lvalue"
> have you tried this "delete (pDoc.getFile());" ?
> if I read the error mesage correctly the compiler thinks you want
do delete
> a function. (I have no compiler nearby so I cant test it)


It's rather the reason mentionned by Kirk & Sean: Attempting to use
the return of a function as a left-value.
So it seems that in this case the pointer invalidation done by
"delete" has lost its meaning, due to the workaround (defining a tmp
reference), because it will invalidate the tmp reference, not the
actual one (m_pFile).. but this is not be a big deal.. "delete" in
C++ doesn't touch the pointer anyway.


> > Another point, I guess D doesn't support "friend" classes or
> > functions.. wouldn't they be useful sometimes?
> Probably but I think they can cause trouble too, it comes down to
weighting
> pros and cons. Something to notice thou is that in D everything in
the same
> module has full access to all fields, as sort of implicit friend
with
> everything in the module.


Yes.. putting the 2 friends in the same module looks like a good
alternative for me.

Thanks friends
John


More information about the Digitalmars-d-learn mailing list