Original Post
Yes, the two parts of C++ that I have the most trouble with, put together! I was wondering if someone could help me with this. I have a graph structure, with nodes and links(sorry, I should have used Verticies and Edges). Link depends on Node, and Node depends on Link, so I remember I'm suppose to do a forward declaration. However it's not working. Also, I think my function pointer in Node class is screwy(as my VS 2005 compiler tells me). Node.h Link.h Can anyone see if anything is popping up as wrong? I don't see where I am going wrong. :(
#pragma once
#include <list>
#include "Link.h"
using namespace std;
class Node
{
public:
double oldValue;
double value;
list<Link*> inputs;
double (*inputFunc)((list<double>) &); // Compiler says something is wrong here!
Node(void)
{
}
~Node(void)
{
}
double getValue()
{
return oldValue;
}
void ComputeValue()
{
list<double> inputValues;
for(list<Link*>::iterator iter = inputs.begin(); iter != inputs.end(); iter++)
inputValues->push_back((*iter)->getValue());
value = (*inputFunc)(inputValues);
}
void CleanUp()
{
oldValue = value;
value = 0.0;
}
};
#pragma once
class Node;
class Link
{
public:
Node* A;
Node* B;
int linkType;
double (*inputFunc)(double);
Link(Node* Alpha, Node* Beta, double (*inputFunction)(double))
{
if(Alpha)
A = Alpha;
if(Beta)
B = Beta;
if(inputFunction)
inputFunc = inputFunction;
}
~Link(void)
{
A = B = NULL;
}
double getValue()
{
return (*inputFunc)(A->getValue());
}
};