Reputation: 181
I am using inheritance for my code. ChangeRequest is my base class. The code is as follows.
ChangeRequest.h
#include <iostream>
#include <string>
using namespace std;
class ChangeRequest
{
int swapDay;
int newDay;
public:
void setSwapDay(int newDay);
int getSwapDay();
void setNewDay(int newDay);
int getNewDay();
};
ChangeRequest.cpp
#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;
}
The code below is for the derived class. SwapDuty SwapDuty.h
#include <iostream>
#include <string>
#include "ChangeRequest.h"
using namespace std;
class SwapDuty: public ChangeRequest
{
string requester;
public:
void setRequester(string member);
string getRequester();
};
SwapDuty.cpp
#include "SwapDuty.h"
void SwapDuty::setRequester(string member)
{
requester = member;
}
string SwapDuty::getRequester()
{
return requester;
}
when I compile and access the requester attribute using getRequester(). I get the following error.
'class ChangeRequest' has no member named 'getRequester'
This is how I used my code
Can someone please tell me what I am doing wrong? Thanks in advance
SwapDuty newSwapDutyRequest;
for(int i = 0; i < tempList.size(); i++ )
{
if(tempList[i].getPersonToPerform().getName() == loginMember)
{
newSwapDutyRequest.setRequester(loginMember);
newSwapDutyRequest.setSwapDay(swapDay);
newSwapDutyRequest.setNewDutyDay(daySwapWith);
break;
}
}
changeList.push_back(newSwapDutyRequest);
cout << changeList[1].getRequester() << endl;
Upvotes: 0
Views: 65
Reputation: 795
What is type of changeList?
Although you have created an object of the derived class, I suspect that you are pushing it into the container of the base class. Possibly you are getting few warnings before this error as well, because of pushing derived object into the container of type base.
If you want to make a container of base class and push in the derived class objects you need to work with the pointers to the objects not the objects themselves.
Upvotes: 1
Reputation: 17272
Where is your class ChangeDutyRequest
? You don't show it. Maybe you forgot to inherit it from the correct base or invoke it incorrectly?
Show fuller code sample
Upvotes: 0