Skip to content

C++ for Bozos: Problems with const

Here’s how to handle problems with the const qualifier: remove it!

For example, if someone has declared a function to return a const object, and you want to use and modify that return value, just change the declared return value.

Example:

[cpp]
void myfunc( std::string s );

const std::string WToA( const std::wstring& w );

myfunc( WToA( w ) ); // will error unless you remove the const!
[/cpp]

Pro Tip:

[cpp]
#define const
[/cpp]