Topic: overloading of operators


Author: hawley@nethris.ucr.edu (brian hawley)
Date: 17 Nov 90 07:39:59 GMT
Raw View
The following has me stumped.

I'm implementing a one dimensional bitvector class.  I want as part
of its operators, union (+), set difference (-).

Other class's use this, and pass as an argument to the constructor,
the size of the bitvector.  For this reason, I had to declare the
instances of the bitvectors as pointers to the bitvector class. (
the size isn't known until runtime.

i.e.

class BitVector {
  char *colptr;
  public:
   BitVector(int size);
   friend BitVector &operator +(BitVector &, BitVector &);
   friend BitVector &operator -(BitVector &, BitVector &);
   BitVector &operator =(BitVector &);
}

// note: the compiler wouldn't let me declare tham as anything but &

class foobar {
 BitVector *vector;
 public:
  foobar(some stuff);
}


At some point during the code, the following call will be made:

foobar::foobar(some stuff) {

 vector = new BitVector(size);
}

In other routines, I want to perform union, difference, (and other
operators) as well as assignments.

I can only get things to partially work, and the c++ book I have
(Dewhurst & Stark) seems only to talk about static instances of
classes in relation to overloaded operators.  So it is little help.


Does anyone have any insight or info?  I've tried several things, and
am still unable to get what I want.


Thanks in advance for any help,

Brian


------------------------------------------------------------------------------
Brian N. Hawley                            Internet: hawley@ucrmath.ucr.edu
Dept. of Math & Computer Science           uucp: {ucsd, uci}!ucrmath!hawley
Univ. of Calif., Riverside, CA 92521       phone: (714) 787-4645