A
Alan
I have a class, "event_list", derived from the template class "vector."
I extended it with a method, "write" for this new class. Here's its
definition:
class event_list : public vector<Event>
{
public:
void write (ofstream &filename, format_type format, int start, int
end);
};
For what it`s worth, the class "Event" is defined thus:
class Event
{
public:
int date;
string name;
string poc;
string type;
Event();
~Event();
void write(ofstream &filename, int start, int end);
};
In the "write" method for "event_list" (derived from vector), I want to
go through every element and write it out. My problem is how to
reference vector methods and operators within this method for the
derived class. I currently have the following code, which will not
compile:
void write (ofstream &filename, format_type format, int start, int end)
{
// write out vector contents
for (int indx = 0; indx < *this.size(); indx++)
{
current_date = *this[indx].date;
if (current_date != last_date)
{
last_date = current_date;
}
*this[indx].write(filename, start, end);
.. . .
};
However, the compiler is telling me that this is and invalid use of
"this" in non-member function (all 3 uses of "this"). I thought this
was the way to do it, since .size() is a function of the STL container
class vector, and "event_list" should inherit this member function.
Could anyone point out what I am doing wrong?
I extended it with a method, "write" for this new class. Here's its
definition:
class event_list : public vector<Event>
{
public:
void write (ofstream &filename, format_type format, int start, int
end);
};
For what it`s worth, the class "Event" is defined thus:
class Event
{
public:
int date;
string name;
string poc;
string type;
Event();
~Event();
void write(ofstream &filename, int start, int end);
};
In the "write" method for "event_list" (derived from vector), I want to
go through every element and write it out. My problem is how to
reference vector methods and operators within this method for the
derived class. I currently have the following code, which will not
compile:
void write (ofstream &filename, format_type format, int start, int end)
{
// write out vector contents
for (int indx = 0; indx < *this.size(); indx++)
{
current_date = *this[indx].date;
if (current_date != last_date)
{
last_date = current_date;
}
*this[indx].write(filename, start, end);
.. . .
};
However, the compiler is telling me that this is and invalid use of
"this" in non-member function (all 3 uses of "this"). I thought this
was the way to do it, since .size() is a function of the STL container
class vector, and "event_list" should inherit this member function.
Could anyone point out what I am doing wrong?