I have an object in my code called a "schemeList" that looks like this:
class scheme;
class schemeList
{
friend class scheme;
private:
scheme * head;
schemeList * tail;
public:
schemeList();
Token addScheme(vector <Token> &toAdd);
//...other functions
};
The function I'm having a problem with is "addScheme" which is supposed to add a scheme to the head, or if the head's full, add it to the tail (in a linked-list kinda way). Here's the function I have so far:
Token schemeList::addScheme(vector<Token>& toAdd)
{
if (head->retCloseParen() != ')')
{
scheme * headCopy = head;
Token answer = head->addScheme(toAdd);
head = headCopy;
return answer;
}
else
{
//deal with tail
schemeList * arrow = this;
while (arrow->tail != NULL)
{
arrow = arrow->tail;
}
tail = new schemeList();
tail->head= new scheme();
tail->tail = NULL;
Token answer = arrow->tail->addScheme(toAdd);
return answer;
}
}
This works fine for adding the first scheme, but the second scheme throws an error that says "Unhandled Exception...". I had a problem like this before but I fixed it by passing the variable toAdd
by reference instead of passing the whole object. Why is this throwing the error and/or how do I fix it?
In case it makes things more clear, a scheme is:
class scheme
{
friend class identifierList;
public:
Token * id;
char openParen;
char closeParen;
identifierList * idList;
scheme();
//other functions
};
class identifierList
{
friend class scheme;
public:
Token * id;
identifierList * next;
identifierList(Token * inId, identifierList * inNext);
};
And a token is:
class Token
{
friend class datalogProgram;
public:
int lineNumber;
string type;
string value;
Token(string inType, string inValue, int inLineNum);
//other functions
};