[ZOOM] pointers

Ashley Sanders zzaascs at irwell.mimas.ac.uk
Thu Nov 1 12:08:56 CET 2001


Okay, why I think we need pointers to resultSets.

Taking my little example function of a few days ago

  void foo (const vector<connection *> &vCon,
            query *psQuery,
            vector<resultSet *> &vSet)
  {         
     vector<connection *>::iterator pvCon;
     for (pvCon = vCon.begin() ; pvCon != vCon.end () ; ++pvCon)
       vSet.push_back (pvCon->search (psQuery));
  }    
       
I think it perfectly legitimate that a user would want
to create an array of result sets. Or if you are using
the STL then a vector of result sets.

If we change connection::search() to return a straight resultSet
object rather than a pointer and change my vector vSet to
vector<resultSet>, then the function becomes:

  void foo (const vector<connection *> &vCon,
            query *psQuery,
            vector<resultSet> &vSet)
  {         
     vector<connection *>::iterator pvCon;
     for (pvCon = vCon.begin() ; pvCon != vCon.end () ; ++pvCon)
       vSet.push_back (pvCon->search (psQuery));
  }    
       
Not much difference there then, but I've just been playing
with g++ 2.95.3 and the line:

       vSet.push_back (pvCon->search (psQuery));

when not using pointers calls a normal constructor once and the
copy constructor twice (why twice I'm not sure.) As we've
agreed that copy constructors on resultSets are banned, then
I wouldn't be able to have my vector of resultSet objects.

I can't think of a way around this, other than using pointers.
As far as I know vector<resultSet &> wont work -- g++ just
barfs with a couple of screens of error messages if I try
that. I presume it's because of the way containers are
implemented in the STL.

Is that good enough reason -- or am I missing something
blindingly obvious?

Ashley.

-- 
Ashley Sanders                                a.sanders at mcc.ac.uk
COPAC: A public bibliographic database from MIMAS, funded by JISC
             http://copac.ac.uk/ - copac at mimas.ac.uk



More information about the ZOOM mailing list