segmention fault with pointers

Pages: 12
ok maybe I have found a first error: changing
1
2
3
4
void And :: setInputs(Component&, Component&){
  *_x1=a;
  *_x2=b;
}

in :
1
2
3
4
void And :: setInputs(Component&, Component&){
  _x1=&a;
  _x2=&b;
}

(and equal for all Other components)
I don't receive any errors
Ok I think it works now.. debugging seems that the binary tree is built.
Now I have to implement a DFS to simulate circuit..
I have (Component*) head of tree, how to move along it?
I mean, I think that to obtain right output of circuit I have to start from the Leaves and do the logicFunction() for each of them.
Then, project asks for min and max path.. How to do this?
None?
trees are usually moved along via recursion.
you pass in head. you want to go left or right
you recurse with the one you want, calling it as if head, and the recursed copy of the function operates on that sub-tree, repeat until done. traversing, you iterate all the pointers, so you basically have 3 operations … do something here, recurse left, recurse right (you can mix this order up as you see fit).
I made this:
1
2
3
4
5
6
void Circuit :: postOrder(Component* node) {
    if(node== nullptr) return;
    postOrder(node->leftChild());
    postOrder(node->rightChild());
    node->logicFunction();
}

but when it's time to do: node->logicFunction(), it doesn't work because it does logicFunction() of class Component, instead of logicFunction of gates (&& if it's a and, || if a or..).
Why?
Last edited on
Just specify it... node->gates::logicfunction();
its caused by how you did your inheritance; whatever you did is finding the component version before the gates version in its search to resolve it.
Topic archived. No new replies allowed.
Pages: 12