[comp.lang.c++] C++ 2.0 bug?

mitch@cadnetix.COM (12/13/89)

I am posting the following for a friend, who does not currently
have access to the net news, but will soon.  If anyone has any 
info/answers/comments on this, would you please EMAIL REPLIES
to me, as I do not read this newsgroup (so little time, too much
to do).  

================== Included Query Begins Here ==================

Will the following code compile on Sun's C++ compiler?  The compilers we have
here (ATT and Oregon Software) get the following error:

"foo.cxx", line 12: error: FOO ::~FOO () with return type

The Oregon Software compiler doesn't like the friend constructor either.
An easy, if sloppy, workaround is to make the entire class FOO a friend of
BAR.  Looking at the source for cfront, I found the following comment:

// define friends defined inline and modify return types if necessary

It would appear that they sometimes tweek the return types of friend
functions, not a nice thing to do if the function is not supposed to
have a return type, as is the case with destructors.  It is really 
too bad ATT wants all that money for support :(

We are supposed to get our fast modem before the end of the year but
until then could you pass this on to comp.lang.c++ to see if anyone
else knows about this?

Thanx.

----------- Code Sample - cut here ----------------


class FOO {
public:
        FOO() { };
        ~FOO() { };
};

class BAR {
public:
        friend FOO::FOO();
        friend FOO::~FOO();
};

===================== End of Included Query ===================

Thanks for your input.  Note that I tried this myself using Sun's
C++ 2.0 compiler, and (as I expected) got the same error message.
Responses can be emailed to me at the address listed below.

                                          -Mitch
                                          
   Mitch Black                UUCP:   ..!{uunet,boulder}!cadnetix!mitch
   Daisy/Cadnetix Corp.   Internet:   mitch@cadnetix.com
   5775 Flatiron Pkwy.
   Boulder, CO 80301         Voice:   (303) 444-8075

mitch@cadnetix.COM (12/16/89)

Once again, I am posting this for my friend, who will soon have access 
to the net (waiting on modem to arrive).  This is a followup to the
original posting, made December 12, with the same "Subject:" line (minus
the "Re:" part, of course).

Again, I must request that you EMAIL REPLIES to me, as I do not read 
this group with regularity.  And a public "Thank you" for all those who 
already have and/or will respond... :-)


=================== Included Query Begins Here =====================

Regarding my posting about a problem with making a destructor a friend 
of another class, I have received a couple of replies suggesting the
following:

>    class A {
>        A();
>        ~A();
>    };
>
>    class B : public A {
>        B();
>        ~B();
>    };

First of all, publicly deriving class B from class A would indeed allow
the access that I desire.  But it is *NOT* the point of the original
posting.  The classes that I am actually working with are *NOT* meant
to be derived from each other; I merely wish that the destructor for
one class be able to get at private data of another class.  I suppose
that I should have stated this more clearly in my original posting, but
I incorrectly assumed that it was obvious from my example.  

Perhaps someone can set me straight, but I don't recall reading in 
any C++ book or documentation, that declaring a destructor to be a friend
of another class is illegal. Additionally our ATT 1.2 C++ compiler 
likes it just fine. (Yes I know that doesn't make it OK.) I realize
that there might be some difficulty with doing this, since destructors are
not supposed to have return types, but I rather suspect that it is something
that just slipped through the cracks in 2.0.  I would like to hear from
either a "Language Lawyer" type person or an implementor with regards to
why this should be prohibited or that it is just a bug.

On a related note,  I have heard rumors about a book that Stroustrup 
(or someone) was working on for language implementors.  Is it real?
Is it in print yet?  I would very much like to get my hands on a copy.

===================== End of Included Query ===================


Responses can be emailed to me at the address listed below.
Thanks again for your time and patience.

                                          -Mitch
   Mitch Black                UUCP:   ..!{uunet,boulder}!cadnetix!mitch
   Daisy/Cadnetix Corp.   Internet:   mitch@cadnetix.com
   5775 Flatiron Pkwy.
   Boulder, CO 80301         Voice:   (303) 444-8075