More C++ Help

Zebra 9

Emperor
Joined
May 17, 2006
Messages
1,554
Location
Middle of Cyberspace
Hi, cotdamn and I finally got the SDK for the evolving civ names to compile with out errors (thank you kael), only problemn was that it would crash when python attempted to use the functions I had exposed to python. I am assuming it has to do with the string types, so I have changed the string type as well as the naming system. Well to my point. cotdamn got this error while attempting to compile the new code:
Code:
CvPlayer.cpp(2029) : error C2664: 'CvInitCore::setLeaderName' : cannot convert parameter 2 from 'CvWString *' to 'const CvWString &'
         Reason: cannot convert from 'CvWString *' to 'const CvWString'
         No constructor could take the source type, or constructor overload resolution was ambiguous
 CvPlayer.cpp(2030) : error C2143: syntax error : missing ';' before '}'
 Process terminated with status 1 (2 minutes, 19 seconds)
 2 errors, 0 warnings
I can't seem to figure out how to fix the problem. Thx for any help.:goodjob:

My source is here.
 
Hello Zebra 9. I can help you.

a CvWString * is a pointer and a CvWString & is a reference.

The two are very similar except that they are used differently and are therefore NOT interchangeable. A reference is used just like an object instance and MUST have a value (i.e. it cannot be null. It must refer to an object that exists). A pointer does not have to be instanced and can be NULL. The following example will help you fix this error.

Code:
void AcceptPointer(SomeObject* pointerToObject)
{
     pointerToObject->AcknowledgeAcceptance(); // methods called by way of pointers must use -> convention
}

void AcceptReference(SomeObject& referenceToObject)
{
     referenceToObject.AcknowledgeAcceptance(); // methods called by way of references use . convention because they act as objects
}

void main()
{
     SomeObject object;
     SomeObject& rObject = object;
     SomeObject* pObject = &object;

     AcceptPointer(pObject1) // will compile... sending a pointer
     AcceptReference(object2) // will compile... passing an object as a reference is ok
     AcceptReference(rObject2) // will compile... passes a reference
     AcceptReference(pObject) // THIS WILL GENERATE YOUR ERROR

     // either pass a reference or code similar to below should fix your problem
     // remember you must always check for a null pointer before sending a derefenced pointer as a reference!
     if (pObject != NULL) AcceptReference(*pObject); 
}
 
It already tells you where your problems are:

CvPlayer.cpp(2029) : error C2664: 'CvInitCore::setLeaderName' : cannot convert parameter 2 from 'CvWString *' to 'const CvWString &'

CvPlayer.cpp(2030) : error C2143: syntax error : missing ';' before '}'
Both of the problems are in CvPlayer.cpp.
The first is on line 2029, the second is on line 2030 (well, actually it's sort of on the same line, but it notices on line 2030).

Change this:
GC.getInitCore().setLeaderName(getID(), name)
to this:
GC.getInitCore().setLeaderName(getID(), &name);

I'm not at a computer with a compiler at the moment, but I'm fairly certain that'll fix it. :)
 
Top Bottom