declaration/overloading error

Fnugus

Chieftain
Joined
Dec 14, 2009
Messages
44
I'm trying to integrate Mylon's Enhanced Sized Cities into my mod, but I keep getting strange errors when trying to compile...

Error code:
Spoiler :
CvCity.cpp(1060) : error C2511: 'int CvCity::getNumPlots(void)' : overloaded member function not found in 'CvCity'
c:\Users\Adder\Desktop\Collection\CvGameCoreDLL\CvCity.h(17) : see declaration of 'CvCity'


in the CvCity.h file, I've added the following:
Code:
int getNumPlots() const;
under the "public:" section of the declaration.

In the CvCity.cpp, at line 1060, I have the copied method:
Spoiler :
// Mylon - enhanced city sizes
int CvCity::getNumPlots()
{
int iRadius;
int var_city_plots;
if (getCultureLevel() == -1)
{
return 9;
}
iRadius = GC.getCultureLevelInfo(getCultureLevel()).getCityRadius();
switch (iRadius)
{
case 4:
var_city_plots = NUM_CITY_PLOTS;
break;
case 3:
var_city_plots = NUM_CITY_PLOTS_3;
break;
case 2:
var_city_plots = NUM_CITY_PLOTS_2;
break;
case 1:
var_city_plots = 9;
break;
default:
var_city_plots = NUM_CITY_PLOTS_2;
break;
}
return(var_city_plots);
} // Mylon - end enhanced city sizes
 
I see the problem...

Code:
// Mylon - enhanced city sizes
[B][COLOR="DarkRed"]int CvCity::getNumPlots()[/COLOR][/B]
{
int iRadius;
int var_city_plots;
if (getCultureLevel() == -1)
{
return 9;
}
iRadius = GC.getCultureLevelInfo(getCultureLevel()).getCityR adius();
switch (iRadius)
{
case 4:
var_city_plots = NUM_CITY_PLOTS;
break;
case 3:
var_city_plots = NUM_CITY_PLOTS_3;
break;
case 2:
var_city_plots = NUM_CITY_PLOTS_2;
break;
case 1:
var_city_plots = 9;
break;
default:
var_city_plots = NUM_CITY_PLOTS_2;
break;
}
return(var_city_plots);
} // Mylon - end enhanced city sizes

Look at the red bolded section above... you are missing const


It should look like this (note the changed red bolded section includes const):

Code:
// Mylon - enhanced city sizes
[B][COLOR="DarkRed"]int CvCity::getNumPlots() const[/COLOR][/B]
{
int iRadius;
int var_city_plots;
if (getCultureLevel() == -1)
{
return 9;
}
iRadius = GC.getCultureLevelInfo(getCultureLevel()).getCityRadius();
switch (iRadius)
{
case 4:
var_city_plots = NUM_CITY_PLOTS;
break;
case 3:
var_city_plots = NUM_CITY_PLOTS_3;
break;
case 2:
var_city_plots = NUM_CITY_PLOTS_2;
break;
case 1:
var_city_plots = 9;
break;
default:
var_city_plots = NUM_CITY_PLOTS_2;
break;
}
return(var_city_plots);
} // Mylon - end enhanced city sizes

That's the problem... I've seen this problem before...
 
Just out of curiosity, what does the "int" and "consts" do on that line, exactly? (I'm guessing that there are constant variables involved and that those are integer values. But why are these mentioned on the function definition line?)

I only know Python and C++ can seem quite alien to me. :rolleyes:
 
Just out of curiosity, what does the "int" and "consts" do on that line, exactly? (I'm guessing that there are constant variables involved and that those are integer values. But why are these mentioned on the function definition line?)

I only know Python and C++ can seem quite alien to me. :rolleyes:

The int is the type of the data that will be returned by the function.

The const is to show that the function is effectively read only and does not modify data contained in the object where the function resides... here: http://msdn.microsoft.com/en-us/library/6ke686zh(VS.80).aspx
 
I see the problem...

Code:
// Mylon - enhanced city sizes
[B][COLOR="DarkRed"]int CvCity::getNumPlots()[/COLOR][/B]
{
int iRadius;
int var_city_plots;
if (getCultureLevel() == -1)
{
return 9;
}
iRadius = GC.getCultureLevelInfo(getCultureLevel()).getCityR adius();
switch (iRadius)
{
case 4:
var_city_plots = NUM_CITY_PLOTS;
break;
case 3:
var_city_plots = NUM_CITY_PLOTS_3;
break;
case 2:
var_city_plots = NUM_CITY_PLOTS_2;
break;
case 1:
var_city_plots = 9;
break;
default:
var_city_plots = NUM_CITY_PLOTS_2;
break;
}
return(var_city_plots);
} // Mylon - end enhanced city sizes

Look at the red bolded section above... you are missing const


It should look like this (note the changed red bolded section includes const):

Code:
// Mylon - enhanced city sizes
[B][COLOR="DarkRed"]int CvCity::getNumPlots() const[/COLOR][/B]
{
int iRadius;
int var_city_plots;
if (getCultureLevel() == -1)
{
return 9;
}
iRadius = GC.getCultureLevelInfo(getCultureLevel()).getCityRadius();
switch (iRadius)
{
case 4:
var_city_plots = NUM_CITY_PLOTS;
break;
case 3:
var_city_plots = NUM_CITY_PLOTS_3;
break;
case 2:
var_city_plots = NUM_CITY_PLOTS_2;
break;
case 1:
var_city_plots = 9;
break;
default:
var_city_plots = NUM_CITY_PLOTS_2;
break;
}
return(var_city_plots);
} // Mylon - end enhanced city sizes

That's the problem... I've seen this problem before...
- That makes sense!

The int is the type of the data that will be returned by the function.

The const is to show that the function is effectively read only and does not modify data contained in the object where the function resides... here: http://msdn.microsoft.com/en-us/library/6ke686zh(VS.80).aspx

That's very helpful too... :)
 
Thanks, that would explain it. This increased my understanding of C++ by 50%. :D (I now know about 3 things about it.)

I strongly believe in understanding what I do instead of just follow a formula without knowing why I should...
 
I strongly believe in understanding what I do instead of just follow a formula without knowing why I should...
That is always good :)
 
Well, it was a hard learned lesson for my part. :p
 
Hmm I guess I have some error tracking to do.. It compiled alright, but caused Civ to crash -.-
 
Ouch... Merging other people's stuff might be harder than to actually do the equivalent thing yourself. Both require some skill, though.
 
Ouch... Merging other people's stuff might be harder than to actually do the equivalent thing yourself. Both require some skill, though.

Yes they do... I suggest running the debugger and trying to figure out what is causing the crash. I typically add break points right where I started adding code and step through until I find the trouble spot... there have been times where I have actually run and crashed the game at least 30-40 times through the development cycle of some of my more complex mod comps.
 
Yes they do... I suggest running the debugger and trying to figure out what is causing the crash. I typically add break points right where I started adding code and step through until I find the trouble spot... there have been times where I have actually run and crashed the game at least 30-40 times through the development cycle of some of my more complex mod comps.

That's going to take some hours xD... And with my very limited C++ skills it's going to take even longer...
 
That's going to take some hours xD... And with my very limited C++ skills it's going to take even longer...
We have to view these things as learning experiences. So just try to understand what it is you're doing and the time invested wont be a waste. :goodjob:
 
We have to view these things as learning experiences. So just try to understand what it is you're doing and the time invested wont be a waste. :goodjob:
True. Although I "*think* I have a pretty good understanding of programming in general, C++ is still somewhat different from other languages I usually use..

Since you changed a header file, I recommend recompiling all files (do a clean build).
This actually worked like a dream. :p
 
Back
Top Bottom