English 中文(简体)
如何不使用 C++ 页眉文件中的命名空间缩进?
原标题:How to shorten the namespace indentation in C++ header files without using using ?

如果您使用命名空间分隔模块/ 结构, 信头文件中的嵌套和缩进会急剧增加。 是否有一种方法可以以较短的方式写入以下代码?

namespace A
{
    namespace B
    {
        namespace C
        {
            namespace D
            {
                namespace E
                {
                    template <typename T>
                    public class X
                    {
                        public: ...

例如,例如

namespace A::B::C::D::E
{
  template<typename T> ...
}

在 c++ 中页眉文件吗?

最佳回答

否, 嵌套的命名空间语法曾经在不同的时间和地点提出过, 但无效 。

不过你不用缩缩缩

namespace A { namespace B { namespace C {
// ...
} } } // namespace A::B::C
问题回答

您可以使用命名空间别名。 这对扩展现有命名空间不起作用, 但更方便访问 。

您可以使用宏来扩展现有的命名空间, < 坚固> 但 您需要这样做, 您可能拥有比您需要或想要更深的命名空间等级 。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签