Hey Frank, I have another ideal, it is better and safer than the last one I mentioned. I add a conversion operator to Reference, instead of a constructor, here is it:
template < class base_interface_type > inline SAL_CALL operator const Reference< base_interface_type > () const SAL_THROW( () ) { return Reference< base_interface_type >( get() ); } I tested some cases, and it works well. How do you think it? I am not very sure it will work for all situation. On Wed, Mar 11, 2009 at 4:05 PM, Frank Schönheit - Sun Microsystems Germany <frank.schoenh...@sun.com> wrote: > Hi Rainman, > >> After a period of time of developing with URE, I find the C++ UNO >> class Reference is not very comfortable for use sometime. >> The problem is, when I have a reference of base interface XA and a >> reference of derived interface XB, I can't make xA = xB directly. >> Instead I have to query XA from xB like this xA = Reference<XA>::query(xB). > > ¨xA = xB.get()¨ would do, too, and be less expensive. > >> I wonder that whether we can use template constructors to simply this >> situation.These constructors may something like this: >> >> template <typename interface_type> >> class Reference >> { >> template <_interface_type> >> Reference(const Reference<_interface_type>& rRef) >> { >> interface_type* p = NULL; >> _interface_type* _p = NULL; >> p = _p; // compiling time cast check. >> _pInterface = iquery( rRef.get() ); > > The last two lines could be to just assigning (and aquiring) rRef.get() > to _pInterface. > >> } >> ... >> Now we can simplify the cast code above to >> xA = xB; > > I am not sure we should do this, implicit constructors usually add > ambiguity ... > > Ciao > Frank > > -- > - Frank Schönheit, Software Engineer frank.schoenh...@sun.com - > - Sun Microsystems http://www.sun.com/staroffice - > - OpenOffice.org Base http://dba.openoffice.org - > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@openoffice.org > For additional commands, e-mail: dev-h...@openoffice.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@openoffice.org For additional commands, e-mail: dev-h...@openoffice.org