I have a function set up so that it receives a function pointer, and that works:
Code:
#include<iostream>
//-----------------
//--My NODE class--
//-----------------
class Node
{
private:
static Node * root;static Node * index;Node * next;
char content;
public:
Node(char content)
{
if (root == NULL)
{
root = this;
next = NULL;
}
else
{
Node * finger = root;
while(!(finger->next==NULL)){finger=finger->next;}
finger->next=this;
this->next=NULL;
}
this->content = content;
}
static void Create(char content)
{
Node * newNode; newNode=new Node(content);
}
static int Count(void)
{
Node * finger; int count=0;
finger=root;
while(!(finger==NULL)){finger=finger->next;++count;};
return count;
}
static void Step(void)
{
if(index==NULL){index=root;}
else{index=index->next;}
}
static char Return(void)
{
return index->content;
}
static void StepLoop(void (*Stepper)(void))
{
for(int x=0;x<Node::Count();x++){Stepper();};
}
};
Node::Node * Node::root = NULL;
Node::Node * Node::index = NULL;
// End of Node class code
void test(void)
{
Node::Step();printf("%c",Node::Return());
}
int main(void)
{
Node::Create('p');Node::Create('p');Node::Create('p');Node::Create('p');
printf("%i\n",Node::Count());
Node::StepLoop(test);
printf("\n");
system("PAUSE");
}
However, I would really rather be able to call
Code:
Node::StepLoop({Node::Step();printf("%c",Node::Return());});
So that I could use StepLoop almost like a FOR block, but specialized for my objects. Is there any way to create a pointer to an anonymous block of code between {} without formally making it into a function?