I have already written a calculator engine that works equally well in both windows and console mode due to it's IO de-coupled design.
My goal now is to extend that functionality to a Calculator class along with it's more generic helper classes. The class I am working on now is the StringList class which will track and traverse a list of user input strings.
Here is where i am unsure. The polymorphic constructor StringList() in one instance will add the StringList object at hand to the single argument, StringList *head. So I am returning *this, but how?
Code:
class StringList
{
StringList *next;
char *string;
StringList *prev;
StringList * StringList::StringList(int thisManyChars)
{ next = NULL; string = NewString(thisManyChars); prev = NULL; return *this;}
StringList * StringList::StringList(StringList *head, thisManyChars)
{ string = NewString(thisManyChars);
StringNode *t = head; while(t->next != NULL) t = t->next;
prev = t; t->next = this; next = NULL; return *this;}
StringList * StringList::StringList(StringList *head)
{ string = NewString(100);
StringNode *t = head; while(t->next != NULL) t = t->next;
prev = t; t->next = this; next = NULL; return *this;}
StringList * StringList::StringList()
{next = NULL; string = NewString(100);
prev = NULL; return *this;}
StringList::~StringList(){ free(string); }
};
Am I using *this properly?