What exactly is the purpose of const at the end of a function? I thought I remembered reading something about it, including the fact that non-const functions cannot call const functions (or something like that).
I'm asking because of a problem I'm having calling CvUnit:
lot(). I have the following code for my unit mission I added:
and this code for boostDiplomacy():
canBoostDiplomacy(CvPlot* pPlot) is another function I added.
Now my mod always crashes when trying to call plot() as the parameter for canBoostDiplomacy(CvPlot* pPlot).
I looked at MISSION_ESPIONAGE and it has the exact same code, substituting espionage() for boostDiplomacy() and canEspionage(const CvPlot* pPlot) for canBoostDiplomacy(CvPlot* pPlot).
Since the game has no problem callling canEspionage(plot()), but for some reason won't call canBoostDiplomacy(plot()), I thought maybe the const highlighted above had something to do with it.
Normally I add const at the end of all my functions, since this appears to be standard. However, it wouldn't let me make boostDiplomacy() const, for some reason, because of NotifyEntity(MISSION_DIPLOMACY).
So, my question is, what exactly does const mean, and does it have anything to do with the problem I'm having? If something totally different (and probably ridiculously obvious) is causing the crash, then point it out, because I am completely baffled why this won't work.
Thanks in advance for the help!
I'm asking because of a problem I'm having calling CvUnit:

Code:
case MISSION_DIPLOMACY:
if (pLoopUnit->boostDiplomacy())
{
bAction = true;
}
break;
and this code for boostDiplomacy():
Code:
bool CvUnit::boostDiplomacy()
{
if (!canBoostDiplomacy(plot()))
{
return false;
}
NotifyEntity(MISSION_DIPLOMACY);
return true;
}
canBoostDiplomacy(CvPlot* pPlot) is another function I added.
Now my mod always crashes when trying to call plot() as the parameter for canBoostDiplomacy(CvPlot* pPlot).
I looked at MISSION_ESPIONAGE and it has the exact same code, substituting espionage() for boostDiplomacy() and canEspionage(const CvPlot* pPlot) for canBoostDiplomacy(CvPlot* pPlot).
Since the game has no problem callling canEspionage(plot()), but for some reason won't call canBoostDiplomacy(plot()), I thought maybe the const highlighted above had something to do with it.
Normally I add const at the end of all my functions, since this appears to be standard. However, it wouldn't let me make boostDiplomacy() const, for some reason, because of NotifyEntity(MISSION_DIPLOMACY).
So, my question is, what exactly does const mean, and does it have anything to do with the problem I'm having? If something totally different (and probably ridiculously obvious) is causing the crash, then point it out, because I am completely baffled why this won't work.
Thanks in advance for the help!