Const (computer programming): Difference between revisions

Content deleted Content added
Expanded volatile section (as it touches const-ness), indented all code to make it more readable, and made various copyedits.
m Methods: Fixed capitalization
Line 28:
int i;
private:
int getGet() const { return i; } // Note the const tag
void setSet( const int j ) { i = j; }
};
 
void Foo( C& nonConstC, const C& constC )
{
int y = nonconstCnonConstC.getGet(); // Ok
int x = constC.getGet(); // Ok: getGet() is const
 
nonConstC.setSet( 10 ); // Ok: nonConstC is modifiable
constC.setSet( 10 ); // Error: setSet() might modify constC!
}
</code>