Tuesday, May 28, 2019

C++ disappointment? Member functions adding parameters?


This seems like such a basic thing:


int foo(int local, int context);​
struct A​
{​
    int context;​
    int foo (int local)​
    {​
        //return foo (local, context);​ // would be nice, but not legal
        return ::foo (local, context);​ // workaround
    }​
};​


And then wrap it in a namespace:

namespace n1​
{​
int foo(int local, int context);​
struct A​
{​
    int context;​
    int foo (int local)​
    {​
        return ::foo (local, context);​ // no longer correct
    }​
};​
}​


it seems to me there are two principles violated here:
  1. I shouldn't have to disambiguate in the first place. The lexical scopes should be merged. Too ambiguous?
2. If I have to disambiguate, code should not have to know what namespace it is in.
I should be able to wrap existing code in namespaces w/o breaking it.

No comments:

Post a Comment