Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing methods after inheritance error
    primarykey
    data
    text
    <p>I am using inheritance for my code. ChangeRequest is my base class. The code is as follows.</p> <p>ChangeRequest.h</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; using namespace std; class ChangeRequest { int swapDay; int newDay; public: void setSwapDay(int newDay); int getSwapDay(); void setNewDay(int newDay); int getNewDay(); </code></pre> <p>};</p> <p>ChangeRequest.cpp</p> <pre><code>#include "ChangeDutyRequest.h" void ChangeRequest::setSwapDay(int newDay) { swapDay = newDay; } int ChangeRequest::getSwapDay() { return swapDay; } void ChangeRequest::setNewDay(int day) { newDay = day; } int ChangeRequest::getNewDay() { return newDay; } </code></pre> <p>The code below is for the derived class. SwapDuty SwapDuty.h</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include "ChangeRequest.h" using namespace std; class SwapDuty: public ChangeRequest { string requester; public: void setRequester(string member); string getRequester(); }; </code></pre> <p>SwapDuty.cpp</p> <pre><code> #include "SwapDuty.h" void SwapDuty::setRequester(string member) { requester = member; } string SwapDuty::getRequester() { return requester; } </code></pre> <p>when I compile and access the requester attribute using getRequester(). I get the following error.</p> <pre><code>'class ChangeRequest' has no member named 'getRequester' </code></pre> <p>This is how I used my code</p> <p>Can someone please tell me what I am doing wrong? Thanks in advance</p> <pre><code> SwapDuty newSwapDutyRequest; for(int i = 0; i &lt; tempList.size(); i++ ) { if(tempList[i].getPersonToPerform().getName() == loginMember) { newSwapDutyRequest.setRequester(loginMember); newSwapDutyRequest.setSwapDay(swapDay); newSwapDutyRequest.setNewDutyDay(daySwapWith); break; } } changeList.push_back(newSwapDutyRequest); cout &lt;&lt; changeList[1].getRequester() &lt;&lt; endl; </code></pre>
    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.
    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