Well actually, I've already tried it with
Code:
WordRecord::WordRecord(vector<string> &vs, string *p)
{
vectorString= vs;
*pLineRec = *p;
}
Where there was no variable to initialize, and that didn't work with the rest of the code either.
To tell you the truth, I'm trying to follow the same thing I did for the Line Record which worked well. But because of the vector, it's confusing me for the constructor, and I'm a little iffy on bringing in the LineRecord into the WordRecord.
Code:
//The Line Record Implementation seems to work ok
LineRecord::LineRecord(string s, string f, int l)
{
sentence = s;
filename = f;
lineNum = l;
}
bool LineRecord::operator >(LineRecord & rhs)
{
if(index == bySentence)
{
return sentence>rhs.sentence;
}
else
{
assert(index == byFile);
return filename>rhs.filename;
}
}
bool LineRecord::operator ==(LineRecord & rhs)
{
return ((sentence==rhs.sentence)&&(filename==rhs.filename)&&(lineNum==rhs.lineNum));
}
ostream& operator << (ostream& ostr, const LineRecord& line)
{
// a little example of C++ formated output
ostr<<setiosflags(ios::left);
ostr<<setw(10);
ostr << line.sentence;
ostr << line.filename;
ostr<< " [";
ostr << line.lineNum;
ostr<< "]";
return ostr;
}
The Word record will include a smilar ostream operator at the end once I've figured out how to declare the constructor.
Code:
//And the class works ok as well
class LineRecord
{
public:
static LineRecordIndex index;
LineRecord(string s,string f,int l);
bool operator >(LineRecord & rhs);
bool operator ==(LineRecord & rhs);
bool operator >=(LineRecord & rhs) {return ((*this) > rhs ) || ((*this) == rhs );}
bool operator <(LineRecord & rhs) {return !((*this) >= rhs );}
bool operator <=(LineRecord & rhs) {return !((*this) < rhs );}
bool operator !=(LineRecord & rhs) {return !((*this) == rhs );}
friend ostream& operator << (ostream& ostr, const LineRecord& p);
private:
string sentence,filename;
int lineNum;
};
ostream& operator << (ostream& ostr, const LineRecord& p);
As I've said, I'm using this Line Record code to guide me into doing the Word Record code