Select to view content in your preferred language

Add const keyword to Get methods on class interfaces

1360
1
04-25-2011 11:41 AM
MichaelSzaszy
New Contributor
Without the const keyword attached to get methods you cannot create any const references to fGDB types.  Example:

void func(const Geodatabase *pGdb)
{
   pGdb->GetDatasetTypes(...);  // Error
}

void func2(const Geodatabase &gdb)
{
   gdb.GetDatasetTypes(...); // Error
}

This prevents us from writing more robust code that is self documenting (const indicating that we will not mutate the state of the object within the code).

Were these attributes omitted because the internal implementation of the fGDB classes do mutate state from the invocation of such methods?  If so does applying mutable to the offending fields resolve any of these internal issues?


Thanks,

Mike
0 Kudos
1 Reply
LanceShipman
Esri Regular Contributor
We have added the const keyword to most Get functions in the 1.1 version of the API. This should allow the writing of more robust code.
0 Kudos