Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ compiler error: "isLeaf() has not been declared" - but it was
    primarykey
    data
    text
    <pre><code>#include &lt;cstdlib&gt; #include &lt;iostream&gt; #include "Node.h" #ifndef HW4_H #define HW4_H using namespace std; /** You are to implement the two functions in this class. You can add any other method or members to it as well. However, you cannot change their signature. **/ class HW4{ public: int count(Node* r) const { if(r-&gt;next==NULL&amp;&amp;r-&gt;bro==NULL) { return 0;} if(r.isLeaf()) { return ((1+count(r-&gt;next)+count(r-&gt;bro))); } count(r-&gt;next); } /* This method will return true if the tree rooted at node sn can answer the demand induced by its leaves. */ bool canDemandBeAnswered(Node* root) { if(count(root)&gt;(root.getCapacity())) { return 0; exit(0); } else { return (canDemandBeAnswered(root-&gt;next)&amp;&amp;canDemandBeAnswered(root-&gt;bro)); } } /* This method should return a linked list of nodes representing the customers with the overall highest revenue. The resulting list should conform to the capacity limitations. */ // Node* getBestCustomers(Node* root); }; #endif #include &lt;cstdlib&gt; #ifndef NODE_H #define NODE_H /** The Node class. You must implement the two methods isLeaf() and addChild(Node*) below. Otherwise, you can add any methods or members your heart's desire. The only limitation is that they have to be in this file. **/ class Node { private: int capacity; int price; public: /** Hint: to be used for saving the Node's children and for returning the linked list **/ Node* next; Node* bro; Node(){ capacity = 0; price = 0; } Node(int capacity_){ capacity = capacity_; price = 0; } //should return true if this node has no children, false otherwise. //this method adds a child to this node. int getCapacity(){ return capacity; } int getPrice(){ return price; } void setPrice(int price_){ price = price_; } bool isLeaf() { if((this-&gt;next)-&gt;capacity==0) return 1; else return 0; } void addChild(Node* child) { Node* temp; if(this-&gt;next!=NULL) { temp=this-&gt;next; child-&gt;bro=temp; this-&gt;next=child; } else this-&gt;next=child; } }; #endif </code></pre> <p>I get the following error: "isLeaf() has not been declared". I don't understand why - I declared both.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload