while(getline(INPUT,textLine))
{
Object* s = new Object(textLine);
}
How would I hold a reference to the Object of the previous textLine so th开发者_JAVA百科at I could compare the two in some compare method
s.Compare(***);
<-- comparing the second iteration to the first
Note that ***
is of type Object
You want to keep track of the previous instance of Object?
Put it in a variable (called t
below), and use the variable when you need it.
Remember to delete everything you allocate.
Object* s;
Object* t = NULL;
while(getline(INPUT,textLine))
{
s = new Object(textLine);
s->Compare(t);
delete t;
t = s;
}
first, see strcmp()
if you want to incorporate this into your "Object" class, which is a bad naming choice, overload the operators !=, ==, > or <, all of them, or only one of them, as you wish/need. Comparison would then go like: if (s > s2) or similar.
Try reading a decent c++ book which covers basic topics as operator overloading and so on.
精彩评论