View Full Version : Simple C++ Errors I need help with


Zebra 9
Aug 31, 2007, 07:23 PM
Ok I'm working on an SDK for the Hand of History and I have gone from about 150 errors (Well that's what I'm guessing seeing as how Shqype had to send them in 2 PMs) 8 (There where 12 but 4 of them was me forgetting the semicoln). Now so you know well over half the changes are just for experimentation. :D

My Errors:c:\Documents and Settings\Shqype\Desktop\Zebra 9\CvGameCoreDLL\CvUnit.cpp(9595): error C2664: 'CyUnit::CyUnit(CvUnit *)' : cannot convert parameter 1 from 'const CvUnit *const ' to 'CvUnit *'
Conversion loses qualifiers
c:\Documents and Settings\Shqype\Desktop\Zebra 9\CvGameCoreDLL\CvUnit.cpp(9555): error C2664: 'CyUnit::CyUnit(CvUnit *)' : cannot convert parameter 1 from 'const CvUnit *const ' to 'CvUnit *'
c:\Documents and Settings\Shqype\Desktop\Zebra 9\CvGameCoreDLL\CvUnit.cpp(8179): error C2664: 'CyUnit::CyUnit(CvUnit *)' : cannot convert parameter 1 from 'const CvUnit *const ' to 'CvUnit *'
Conversion loses qualifiers
c:\Documents and Settings\Shqype\Desktop\Zebra 9\CvGameCoreDLL\CvUnit.cpp(8132): error C2664: 'CyUnit::CyUnit(CvUnit *)' : cannot convert parameter 1 from 'const CvUnit *const ' to 'CvUnit *'
Conversion loses qualifiers
c:\Documents and Settings\Shqype\Desktop\Zebra 9\CvGameCoreDLL\CvUnit.cpp(6989): error C2664: 'CyUnit::CyUnit(CvUnit *)' : cannot convert parameter 1 from 'const CvUnit *const ' to 'CvUnit *'
Conversion loses qualifiers
c:\Documents and Settings\Shqype\Desktop\Zebra 9\CvGameCoreDLL\CvUnit.cpp(6084): error C2664: 'CyUnit::CyUnit(CvUnit *)' : cannot convert parameter 1 from 'const CvUnit *const ' to 'CvUnit *'
Conversion loses qualifiers
c:\Documents and Settings\Shqype\Desktop\Zebra 9\CvGameCoreDLL\CvUnit.cpp(2780): error C2664: 'CyUnit::CyUnit(CvUnit *)' : cannot convert parameter 1 from 'const CvUnit *const ' to 'CvUnit *'
Conversion loses qualifiers
c:\Documents and Settings\Shqype\Desktop\Zebra 9\CvGameCoreDLL\CvUnit.cpp(2779): error C2664: 'CyUnit::CyUnit(CvUnit *)' : cannot convert parameter 1 from 'const CvUnit *' to 'CvUnit *'

Now the only spot's where I'm getting these errors are inside of functions which are const. And it's saying somthing about coverting from const to no const.

Kael
Aug 31, 2007, 08:14 PM
Const means it will always have the same value. A const function cannot call a non-const function. But your going to have to link some of those lines if you want more feedback.

Zebra 9
Sep 01, 2007, 02:13 PM
The first error is in here:
bool CvUnit::isAmphib() const
{
// Edited by Zebra 9 for THH's Improved Great Generals
if ( GC.getDefineINT("USE_IS_UNIT_AMPHIB_CALLBACK") == 1 )
{
CyArgsList argsList;
CyUnit* pyUnit = new CyUnit(this); //Line #9595
argsList.add(gDLL->getPythonIFace()->makePythonObject(pyUnit)); // pass in unit class

long lResult=0;

gDLL->getPythonIFace()->callFunction(PYGameModule, "isUnitAmphib", argsList.makeFunctionArgs(), &lResult);
delete pyUnit; // python fxn must not hold on to this pointer
if (lResult >= 1)
{
return true;
}
else if (lResult == 0)
{
return false;
}
}
// End Edit
return (getAmphibCount() > 0);
}

the next error:
bool CvUnit::isBlitz() const
{
// Edited by Zebra 9 for THH's Improved Great Generals
if ( GC.getDefineINT("USE_IS_UNIT_BLITZ_CALLBACK") == 1 )
{
CyArgsList argsList;
CyUnit* pyUnit = new CyUnit(this); //Line #9555
argsList.add(gDLL->getPythonIFace()->makePythonObject(pyUnit)); // pass in unit class

long lResult=0;

gDLL->getPythonIFace()->callFunction(PYGameModule, "isUnitBlitz", argsList.makeFunctionArgs(), &lResult);
delete pyUnit; // python fxn must not hold on to this pointer
if (lResult >= 1)
{
return true;
}
else if (lResult == 0)
{
return false;
}
}
// End Edit
return (getBlitzCount() > 0);
}
next:

bool CvUnit::isNukeImmune() const
{
// Edited by Zebra 9 for THH's Improved Great Generals
if ( GC.getDefineINT("USE_IS_UNIT_NUKE_IMMUNE_CALLBACK") == 1 )
{
CyArgsList argsList;
CyUnit* pyUnit = new CyUnit(this); //8179
argsList.add(gDLL->getPythonIFace()->makePythonObject(pyUnit)); // pass in unit class

long lResult=0;

gDLL->getPythonIFace()->callFunction(PYGameModule, "isUnitNukeImmune", argsList.makeFunctionArgs(), &lResult);
delete pyUnit; // python fxn must not hold on to this pointer
if (lResult >= 1)
{
return true;
}
else if (lResult == 0)
{
return false;
}
}
// End Edit
return m_pUnitInfo->isNukeImmune();
}

They are all the same thing so it is of no use showing all of them.:goodjob:

Now I knew what the const meant, but I did not know that you couldn't call a non const function from a const function. So how would I fix this. I think I could rename the functions and make a function that uses my changes and calls the renamed function. Would that work?

Edit: Those are not all for THH's improved GGs, I just kept copying the same code. :D

MatzeHH
Sep 01, 2007, 02:46 PM
Don't use CyUnit.
All Cy... are only wrappers to use the Cv... classes in Python.
Use CvUnit instead.
You will have access to your functions from Python as well.

Matze

snarko
Sep 01, 2007, 02:55 PM
Try using CyUnit* pyUnit = new CyUnit((CvUnit*)this);

Zebra 9
Sep 01, 2007, 03:33 PM
So would this work as well:CyUnit* pyUnit2 = new CyUnit((CvUnit*)this);I'm assuming yes.