Argh! Shadowing parameters --> fooey

I tend towards two things, both with the same goal in mind:
1. Providing an ADT that uses meaningful names to the user
2. Using meaningful names in my code

Sometimes these clash.
1
2
3
4
  bool resource_t::update( const std::string& newfilename )
    {
    std::string newfilename( newfilename );
    ...

Too bad the compiler can't realize that it entirely obvious that I meant to do that...

Why would I do that, some might ask?
I would answer: why would I give the same value two different names?

The next question is then, why use two variables; why not just make the argument non-const?
The answer is, because the const argument means that the user can say:
1
2

r.update( "fooey.txt" );

and
1
2
char name[] = "fooey.txt";
r.update( name );

where if it is not const, he can't. He would instead have to explicitly construct strings:
1
2

r.update( string( "fooey.txt" ) );

Most inconvenient.

So, choosing the lesser of two evils, I must use some dumb variation on my variable name so the compiler won't regurgitate on a variable name that directly shadows another.

Poop.
Topic archived. No new replies allowed.