diff options
-rw-r--r-- | GateAnd.cpp | 2 | ||||
-rw-r--r-- | Node.cpp | 1 | ||||
-rw-r--r-- | main.cpp | 24 |
3 files changed, 16 insertions, 11 deletions
diff --git a/GateAnd.cpp b/GateAnd.cpp index d14d7f6..487f8bc 100644 --- a/GateAnd.cpp +++ b/GateAnd.cpp @@ -9,7 +9,7 @@ SignalLevel GateAnd::level() { if (this->inputs.size() < 1) throw CircuitException("AndGate input size error"); for (int i = 0; i < this->inputs.size(); i++){ - SignalLevel l this->inputs[i]->getLevel(); + SignalLevel l = this->inputs[i]->getLevel(); if (l == UNDEFINED) return UNDEFINED; if (l == LOW) return LOW; @@ -10,6 +10,7 @@ Node::Node(const char * type) { void Node::addInput(Net * net) { net->attach(this); + inputs.push_back(net); } void Node::setOutput(Net * net){ @@ -15,16 +15,20 @@ int main() { // Observer ob(); Net n, n1, o; Node *g = new GateAnd; - g->addInput(&n); - g->addInput(&n1); - g->setOutput(&o); - - // o.setLevel(UNDEFINED); - n.setLevel(LOW); - n1.setLevel(LOW); - int level = 22; - level = o.getLevel(); - printf("hello world! %d\n", level); + try { + g->addInput(&n); + g->addInput(&n1); + g->setOutput(&o); + + // o.setLevel(UNDEFINED); + n.setLevel(HIGH); + n1.setLevel(HIGH); + int level = 22; + level = o.getLevel(); + printf("hello world! %d\n", level); + } catch(Exception& e) { + std::cerr << e.what() << '\n'; + } return 0; } |