0
내가 내 코드에서 객체가이처럼 보이는 "schemeList"를 불렀다 매개 변수 메모리 문제로 통과 ++ :C는 재귀 적으로
class scheme;
class schemeList
{
friend class scheme;
private:
scheme * head;
schemeList * tail;
public:
schemeList();
Token addScheme(vector <Token> &toAdd);
//...other functions
};
나는에 문제가 있어요 기능은 가정된다 "addScheme"입니다 머리에 스킴을 추가하거나, 머리가 가득차면 꼬리에 꼬리말을 추가하십시오 (링크 된리스트에서).
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;
}
}
이 첫 번째 방식을 추가하기위한 잘 작동하지만 두 번째 체계라는 오류가 발생합니다 "처리되지 않은 예외 ..."여기에 지금까지 가지고있는 기능입니다. 전에 이런 문제가 있었지만 전체 객체를 전달하는 대신 변수 toAdd
을 참조로 고정하여 해결했습니다. 왜 이것이 오류를 던지거나 해결할 수 있습니까?
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);
};
그리고 토큰은 다음과 같습니다 : 경우
가이 일을 더 명확하게하는 방식이다
class Token
{
friend class datalogProgram;
public:
int lineNumber;
string type;
string value;
Token(string inType, string inValue, int inLineNum);
//other functions
};
연결된 목록을 재 작성하는 데 시간을 낭비하지 말고'std :: list' 또는'std :: vector'를 사용해야합니다. –
'scheme :: addScheme' 구현을 보여주세요. 그리고 예외를 얻는 호출 스택. – Paul