The last resort :
...If someone could do the honors...
Code:
#include <iostream>
#include <string>
#include <list>
using namespace std;
class Sstring{
private:
char *toStr;
public:
Sstring(char *s){
toStr=new char[strlen(s)+1];
strcpy(toStr, s);
}
~Sstring(){if (toStr) delete [] toStr;}
void dsp(void){cout<<toStr;}
char* gets(){return toStr;}
friend bool operator < (const Sstring* s1, const Sstring* s2){
bool rv= s1->toStr[0] < s2->toStr[0];
cout<<endl<<" rv = "<<rv<<endl;
return rv;
}
};
class Holder{
private:
list<Sstring *> theList;
public:
void addMe(Sstring *IN){
theList.push_front(IN);
}
void dsp_all(){
list<Sstring *>::iterator i = theList.begin();
cout<<endl<<"--TOP--"<<endl<<endl;
while(i != theList.end()){
(*i)->dsp();//toStr;
cout<<endl;
i++;
}
cout<<endl<<"--END--"<<endl;
}
void ListSort(){
cout<<"Holder::ListSort()"<<endl;
theList.sort(op);
}
bool op(const Sstring* s1, const Sstring* s2){
return *s1 < *s2;
}
};
int main (void){
Holder h;
Sstring a("ANumber One");
Sstring b("BNumber Two");
Sstring c("CNumber Three");
h.addMe(&a);
h.addMe(&b);
h.addMe(&c);
h.dsp_all();
h.ListSort();
h.dsp_all();
return 1;
}