I'd like to use a STL std::vector<nsCOMPtr<nsISomething> > component
_internally_,
that is as a non-interfaced member variable of a XPCOM class.
I get an compilation error which correctly states that the following
conversion operator
is private:
nsCOMPtr<T> *nsCOMPtr<T>::operator& ()
Whats the deeper rational behind this? I understand that its bad to pass
nsCOMPtr
as out parameters. But is it really intended to break any usage of nsCOMPtrs
with
STL containers?? Is this a problem of my STL implementation or am I missing
something
important with nsCOMPtrs?
I've full-text searched through the >8000 msgs on this group and only found
4 msgs
containing "vector": responses to someone who wanted to discuss the general
rejection
of templates or the use of STL containers with interfaces. The former is
boring, the latter is crap.
Nothin' else found. Please help.
Toby.
nsCOMPtr.h
688 private:
689 const nsCOMPtr<T>*
690 operator&() const
691 // This is private to prevent accidental use of |operator&|
692 // instead of |getter_AddRefs|, which can happen if the result
693 // is cast.
694
695 // To pass an nsCOMPtr as an out parameter to a function,
either
696 // (preferably) pass by reference or use |address_of|.
697 {
698 return this;
699 }
700
701 nsCOMPtr<T>*
702 operator&()
703 // This version is also needed so things will compile before
704 // all the uses are removed and we make it private. After
it's
705 // private, we won't need two anymore.
706 {
707 return this;
708 }
[toberste@bluebox omk]$ gmake
Removing old dependencies file, .deps/.all.pp
gmake export
gmake[1]: Entering directory
`/home/toberste/xpcom-standalone/mozilla/xpcom/bt/btcomponents/omk'
../../../../config/nsinstall -R -m 644 btISeries.idl btISeriesUint8.idl
btISequenceSeries.idl btISampledSeries.idl btIPointSeries.idl
../../../../dist/idl
../../../../config/nsinstall -R -m 644 _xpidlgen/btISeries.h
_xpidlgen/btISeriesUint8.h _xpidlgen/btISequenceSeries.h
_xpidlgen/btISampledSeries.h _xpidlgen/btIPointSeries.h
../../../../dist/include/xpcom/usr/bin/perl5 -I../../../../config
../../../../config/build-list.pl ../../../../dist/include/xpcom/.headerlist
btISeries.h btISeriesUint8.h btISequenceSeries.h btISampledSeries.h
btIPointSeries.h
gmake[1]: Leaving directory
`/home/toberste/xpcom-standalone/mozilla/xpcom/bt/btcomponents/omk'
gmake libs
gmake[1]: Entering directory
`/home/toberste/xpcom-standalone/mozilla/xpcom/bt/btcomponents/omk'
omk.cpp
c++ -o
omk.o -c -DXPCONNECT_STANDALONE -DOSTYPE=\"Linux2.4\" -DOSARCH=\"Linux\" -DO
JI -I../../../../dist/include/string -I../../../../dist/include/btbase -I..
/../../../dist/include/xpcom -I../../../../dist/include -I/home/toberste/xpc
om-standalone/mozilla/dist/include/nspr -I/usr/X11R6/include -fPIC -
I/usr/X11R6/include -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-a
rith -Wbad-function-cast -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor
-dtor-privacy -pedantic -Wno-long-long -fshort-wchar -pthread -pipe -DNDEBU
G -DTRIMMED -O -I/usr/X11R6/include -DMOZILLA_CLIENT -include
../../../../config-defs.h -Wp,-MD,.deps/omk.pp omk.cpp
/usr/include/g++-3/stl_construct.h: In function `void __destroy_aux
(_ForwardIterator, _ForwardIterator, __false_type) [with
_ForwardIterator = nsCOMPtr<btIBuffer> *]':
btCSeries.i:73: instantiated from `btCSeriesBase<TM, VT>::btCSeriesBase ()
[with TM = btTmSequence,
VT = btVtUint8]'
btCSeries.i:196: instantiated from `btCSeries<btTmSequence, VT>::btCSeries
() [with VT = btVtUint8]'omk.cpp:58: instantiated from here
../../../../dist/include/xpcom/nsCOMPtr.h:707: `nsCOMPtr<T>
*nsCOMPtr<T>::operator& () [with T =
btIBuffer]' is private
/usr/include/g++-3/stl_construct.h:61: within this context
btCSeries.h: At top level:
omk.cpp:44: warning: `const char *rcsid' defined but not used
gmake[1]: *** [omk.o] Error 1
gmake[1]: Leaving directory
`/home/toberste/xpcom-standalone/mozilla/xpcom/bt/btcomponents/omk'
gmake: *** [all] Error 2