Hey there; I've been working on a really simple class for a void pointer linked list. I'm looking for a way to deal with having to convert to void* and then back to whatever type I'm using. For example:
My class:
Code:struct GSLLNODE { void* dat; GSLLNODE* next; }; class GSLL { private: GSLLNODE *root; public: GSLL() {root = new GSLLNODE; root->next = 0;} void Next(void* dat); void* GetNext(); }; void GSLL::Next(void* dat) { GSLLNODE *n = new GSLLNODE; GSLLNODE *cur = root; n->dat = dat; n->next = 0; while(cur->next) cur = cur->next; cur->next = n; } void* GSLL::GetNext() { if(!root->next) return 0; root = root->next; return root->dat; }I suppose I'm looking for some sort of auto-interface to cast the void pointer automatically? It'd help cut the amount of neccesary coding drastically.Code:int main() { GSLL gg; int f = 0; gg.Next((void*)++f); gg.Next((void*)++f); gg.Next((void*)++f); gg.Next((void*)++f); gg.Next((void*)++f); gg.Next((void*)++f); f = (int)gg.GetNext(); while(f) { std::cout << f; f = (int)gg.GetNext(); } std::cin >> f; return 0; }