I'm having trouble kids... systems programming is kicking my ass and I've returned from a long hiatus at work for help.
Code:
#include <iostream>
#include <string>
#include "Item.h"
using namespace std;
template < class AT >
struct NODE{
Item<AT> * attrib;
NODE<AT> * next;
};
template< class AT >
class SymTab {
public:
SymTab(); // Initializes the empty table, a vector of 157 linked list heads.
Item< AT > * find( string s ); // Returns Item pointer or NULL
Item< AT > * insert( string s ); // Returns Item pointer to inserted string
private:
int hash( string s ); // Returns bucket hashed to (0 <= return value <= 156)
NODE<AT> *Table[157];
};
//constructor
template < class AT >
SymTab< AT >::SymTab()
{
for(i=0; i < 157
}
//find, locates items in the table and returns pointers to them or null
template < class AT >
Item<AT>* SymTab< AT >::find( string s )
{
int value, i=0, Fspace = 0, Lspace = 0;
string OpCode, Hex;
char Sic;
Item<AT> * ItemPtr;
//Splits up the string into OpCode, Hex value and S or X for Sic or Sic/XE
Fspace = s.find(' ');
Lspace = s.rfind(' ');
cout << "First: " << Fspace << endl;
cout << "Last: " << Fspace << endl;
OpCode = s.substr(0, Fspace);
Hex = s.substr(Fspace+1, 2);
Sic = s[s.length()-1];
//Done splitting
value = hash(OpCode);
if(Table[value]->next->item->name == s)
ItemPtr = SymTab[value];
return ItemPtr;
}
//insert, puts items into the table.
template < class AT >
Item<AT>* SymTab<AT>::insert( string s )
{
int value, i=0, Fspace = 0, Lspace = 0;
string OpCode, Hex;
char Sic;
Item<AT> * ItemPtr;
//Splits up the string into OpCode, Hex value and S or X for Sic or Sic/XE
Fspace = s.find(' ');
Lspace = s.rfind(' ');
cout << "First: " << Fspace << endl;
cout << "Last: " << Fspace << endl;
OpCode = s.substr(0, Fspace);
Hex = s.substr(Fspace+1, 2);
Sic = s[s.length()-1];
//Done splitting
value = hash(OpCode); // Gets the hash value from the OpCode
ItemPtr = new Item<AT>(OpCode);
cout << "a" << endl;
Table[value]->attrib = ItemPtr;
cout << &Table[value]->attrib << endl;//= ItemPtr;
cout << "a" << endl;
//if(the SymTab[value] is occupied && it's not occupied by the same value)
//{
//set flag to different
//}
//else (SymTab[value] is not occupied)
//Set ItemPtr and point SymTab[value]'s pointer to it.
return ItemPtr;
}
template < class AT >
int SymTab<AT>::hash(string s)
{
int hash_value=0, i=0, int_cast=0, size = 10;
int Poly[10];
for(i=0; i < size; i++)
{
int_cast = int(s[i]);
Poly[i] = int_cast;
}
for(i=0; i < s.length(); i++)
{
hash_value += (s[i] * 256);
}
hash_value %= 157;
cout << "hash_value: " << hash_value << endl;
return hash_value;
}
My issue is that the bold line just ain't cutting it. For some reason the pointers just aren't assigning properly.