不同名称空间中具有相同名称的类

thr*_*unt 2 c++ naming namespaces

我正在写一个图书馆.有两个具有相同名称的类但每个类都在不同的名称空间中是不是一个坏主意?

使用名称空间:

//forward declaration
namespace sparse {
    class matrix;
}
namespace dense {
    class matrix;
}

namespace dense {
    typedef Index uint64_t;
    class matrix {
        public:
        sparse::matrix tosparse();
    };
}

namespace sparse {
    typedef Index uint32_t;
    class matrix {
        dense::matrix todense();
    };
}
Run Code Online (Sandbox Code Playgroud)

或者,我可以使用长名称:

class sparse_matrix
...
Run Code Online (Sandbox Code Playgroud)

Pet*_*ker 5

一般来说,那没关系.这正是命名空间的用途.在这个例子中,不清楚设计目标是什么,因此不清楚这是否适当使用命名空间.