Topic: Why does not allow to override point operator?


Author: "Alexey N. Solofnenko" <trelony@typhoon.spb.ru>
Date: 1998/02/18
Raw View
Hi!

  Sometimes using aggregation pattern we need to enable access to some
interfaces of inner object. Right now we have only one way - by
redeclaring most (?all?) methods in outer object. It would duplicate
interfaces and make it difficult to support. And point operator could
help - if compiler did not find required attribute in the class it
could look for point operator(s) and try to find the attribute in types
these operators return.

Best wishes,
  Alexey Solofnenko.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Gerard Weatherby <gerardw@alum.mit.edu>
Date: 1998/02/19
Raw View
Alexey N. Solofnenko wrote:
>
> Hi!
>
>   Sometimes using aggregation pattern we need to enable access to some
> interfaces of inner object. Right now we have only one way - by
> redeclaring most (?all?) methods in outer object. It would duplicate
> interfaces and make it difficult to support. And point operator could
> help - if compiler did not find required attribute in the class it
> could look for point operator(s) and try to find the attribute in types
> these operators return.
>
> Best wishes,
>   Alexey Solofnenko.
If it's feasible to derive from the inner object, you can do this
selectively with private inheritance and the using keyword.

struct Inner {
 A( );
 B( );
 C( );
};

struct Outer : private Inner
{
 X( );
 Y( );
 using Inner::A;
 using Inner::B;
}

where, given Outer outer,
 outer.X( ) and outer.Y( ) calls the aggregate functions,
 and outer.A( ) and outer.B( ) call the inner object functions,
 and outer.C()  is prohibited.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Alexey N. Solofnenko" <trelony@typhoon.spb.ru>
Date: 1998/02/19
Raw View
Hi, Gerard!

  In fact I mean something like:

class T : public objectof T2 {...}; // it is more general

At compile time it is not known what object of what class will be the
"parent" of new one. It is like in OLE. In need to override some global
interface of some object which class is inherited from some given. By
overriding point operator I could only resolve one problem - changing
global interface (T2 object would not know that he was "overridden").
It could help in situations when smart pointers work like the objects.
With operator -> it is not easy to call inner object's operators. Maybe
it looks like trick - too powerful construct on low level. Maybe more
general case (like I wrote in this letter) is better. Lets discuss it.

Best regards,
  Alexey Solofnenko.

Gerard Weatherby wrote:

> If it's feasible to derive from the inner object, you can do this
> selectively with private inheritance and the using keyword.
>
> struct Inner {
>         A( );
>         B( );
>         C( );
> };
>
> struct Outer : private Inner
> {
>         X( );
>         Y( );
>         using Inner::A;
>         using Inner::B;
> }
>
> where, given Outer outer,
>         outer.X( ) and outer.Y( ) calls the aggregate functions,
>         and outer.A( ) and outer.B( ) call the inner object functions,
>         and outer.C()  is prohibited.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]