• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

werid issue with C++ functions and default values

Red Squirrel

No Lifer
IT's my understanding that if you do something like this:

Code:
void DataObject::Load(mysqlpp::Row row,bool childfields=true)
{
//stuff
}


That function can be called without the 2nd argument because I provided a default value. The problem is, I noticed sometimes this works, sometimes it does not (wont compile). Why is that?
 
IT's my understanding that if you do something like this:

Code:
void DataObject::Load(mysqlpp::Row row,bool childfields=true)
{
//stuff
}


That function can be called without the 2nd argument because I provided a default value. The problem is, I noticed sometimes this works, sometimes it does not (wont compile). Why is that?

Try putting your default values in the function declaration (i.e., in the header), not in the function definition.
 
Thanks that seems to have done it. I don't know why I thought I had to set it in the function itself. Makes more sense in the declaration. Will also make my life easier as I tend to use my declaration classes as a form of documentation as I see all the function names right off the bat so now I'll see the defaults too without having to comment them separately.
 
Back
Top