🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Kim Coleman Tue, 28 Mar 1989 17:59
g++ 1.34.1 & private base classes
#1804
Author: Kim Coleman
Date: Tue, 28 Mar 1989 17:59
44 lines
1927 bytes
//  Test that compiler correctly handles private base classes. In particular,
//  an implicit conversion from a derived pointer to a base pointer should
//  only be made when the base class is public. See Stroustrap, p. 197.
//
//  Actually, g++ carries this rule even farther and performs implicit
//  conversions on objects and references as well as pointers. Though this
//  doesn't conform to The Book, if you're going to do this, it should
//  follow the same rules as pointers regarding private base classes.
//  As demonstrated below, this is only partially true.

class base {
    int i;
public:
    base()   {i = 0;}
    base (int x)  {i = x;}
    do_something (base& param) {;}
};

class derived : base {
    int j;
public:
     derived() {j = 0;}
};

main()
{
   base     base_obj;
   derived  derived_obj;

      //
      // The following statements should be in error on one hand because
      // you can only perform implicit pointer conversions between derived
      // and base class objects. However, even if you accept this behavior,
      // they should still be in error because <base> is private.
      //
   base_obj = derived_obj;                // g++ 1.34.1 only catches this
   base_obj.do_something (derived_obj);   // should also be an error
}

-------------------------------------
Kim Coleman
Data General Corp., Research Triangle Park, NC
{the world}!mcnc!rti!dg-rtp!coleman
g++ 1.34.1 & private base classes
#1948
Author: Michael Tiemann
Date: Wed, 03 May 1989 04:02
36 lines
1301 bytes
   class Object
   {
   public:
      virtual Object* some_method (const Object&);
   };
   
   
   class Collection_Member : public Object
   {};
   
   
   class Collection : public Object
   {
   public:
				    // this is what I WANT to do
      Collection_Member*  some_method (const Collection_Member&);
You can do this now (but this will be a *different* virtual function
then the one above.
   
   //
   // in desparation, I also tried:
   //
				    // g++ 1.34.1 accepts this form
No longer.
   //   Collection_Member*  some_method (const Object&);

Again, a *different* virtual function.
   //   Object*             some_method (const Collection_Member&);
   
				    // cfront only accepts this form
As does GNU C++.
   //   Object*             some_method (const Object&);
   };

Michael
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads