Simple C++ Errors I need help with

Zebra 9

Emperor
Joined
May 17, 2006
Messages
1,554
Location
Middle of Cyberspace
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:
Code:
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.
 

Attachments

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.
 
The first error is in here:
Code:
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;
[B]		CyUnit* pyUnit = new CyUnit(this); //Line #9595[/B]
		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:
Code:
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;
[B]		CyUnit* pyUnit = new CyUnit(this); //Line #9555[/B]
		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:
Code:
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;
[B]		CyUnit* pyUnit = new CyUnit(this); //8179[/B]
		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
 
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
 
Try using CyUnit* pyUnit = new CyUnit((CvUnit*)this);
 
Back
Top Bottom