Is this standard in C++? In C#, I liked declaring nested namespaces like this:
namespace A.B
{
class X
{
};
}
The alternative was this, which is a little uglier:
namespace A
{
namespace B
{
class X
{
};
}
}
In C++, I wanted to see if it had a similar feature. I ended up finding this works:
namespace A::B
{
class Vector2D
{
}
}
Notice the ::
.
I'm curious if this is standard C++ or if this is a MS feature. I can't find any documentation on it. My ancient C++98 reference book doesn't mention it, so I wonder if it's an extension from Microsoft or a new feature.
Yes, this is legal C++ 17 syntax. It is, however, not called embedded namespace, but nested namespace.
namespace
ns_name::
name (8) (since C++17)[...]
8) nested namespace definition:
namespace A::B::C { ... }
is equivalent tonamespace A { namespace B { namespace C { ... } } }
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With