Date: Sat, 29 Apr 2023 02:52:11 +0300
On Sat, 29 Apr 2023 at 02:46, Bjarne Stroustrup <bjarne_at_[hidden]> wrote:
>
> One of the first things I tried was this
>
>
> import std;
>
> namespace PPP {
> using namespace std;
> struct vector { void found_our_own() {} };
> }
>
> using namespace PPP;
This is the problem; you can't do that using-directive.
> int main() {
> string s;
> vector v;
> v.found_our_own();
> }
>
>
> It would have been ideal for my purposes. I get a double definition of
> vector error. language problem? My confusion? Compiler bug?
The compiler implements the language correctly here. You *do* have two
vectors in namespace PPP,
but lookup will prefer the one you defined or user-declared in that
namespace, if you use qualified names. If you bring every name in PPP
into another scope, it'll bring both vectors into scope, and then
that's ambiguous.
Name lookup in C++ is complicated. :P
>
> One of the first things I tried was this
>
>
> import std;
>
> namespace PPP {
> using namespace std;
> struct vector { void found_our_own() {} };
> }
>
> using namespace PPP;
This is the problem; you can't do that using-directive.
> int main() {
> string s;
> vector v;
> v.found_our_own();
> }
>
>
> It would have been ideal for my purposes. I get a double definition of
> vector error. language problem? My confusion? Compiler bug?
The compiler implements the language correctly here. You *do* have two
vectors in namespace PPP,
but lookup will prefer the one you defined or user-declared in that
namespace, if you use qualified names. If you bring every name in PPP
into another scope, it'll bring both vectors into scope, and then
that's ambiguous.
Name lookup in C++ is complicated. :P
Received on 2023-04-28 23:52:23