hi everyone! i am writing a symbol table, and originally had it working as a std::vector<Token> (Token is my class to hold an entry in the symbol table) I realized that i was just going to be continuosly iterating over it and not actually ever looking up, so i decided to write in a linked list, for more efficiency, and because it was time to learn how to write one. however when i went to write it I got segment fault(core dumped) but i dont know where the memory issue is
here it Token.cpp:
Code:
#include <iostream>
#include <string>
#include "Token.hpp"
using namespace std;
using std::string;
Token::Token() {}
Token::Token(string type, string name, long line, long column)
: Type(type), Name(name), Line(line), Column(column) {}
void Token::SetType (string type) { this->Type = type; }
void Token::SetName (string name) { this->Name = name; }
void Token::SetLine (long line) { this->Line = line; }
void Token::SetColumn (long column) { this->Column = column; }
string Token::GetType () { return this->Type; }
string Token::GetName () { return this->Name; }
long Token::GetLine () { return this->Line; }
long Token::GetColumn () { return this->Column; }
Token* Token::Begin() { return this->Start; }
void Token::Next () { *this = *this->Next_; this->Finish = this; }
Token* Token::End () { return Finish; }
int main(int argc, char *argv[])
{
Token *TokenList = new Token;
for(int Counter = 0; Counter < 10; Counter++)
{
TokenList = new Token("test", "test", Counter, Counter);
TokenList->Next();
}
for(Token::Iterator Counter = TokenList->Begin(); Counter != TokenList->End(); Counter++)
cout<< "no";
}
(when i get it write im taking out the using namespace std, iostream header, and main function but i need it right now for testing)
Token.hpp
Code:
#ifndef _Token_hpp
#define _Token_hpp
#include <string>
using std::string;
class Token
{
string Type, Name;
long Line, Column;
Token *Start = this, *Next_, *Finish;
public:
Token();
Token(string, string, long, long);
void SetType (string);
void SetName (string);
void SetLine (long);
void SetColumn (long);
string GetType ();
string GetName ();
long GetLine ();
long GetColumn ();
Token* Begin();
void Next ();
Token* End ();
typedef Token* Iterator;
};
#endif