我正在编写一个库。把两个类命名相同但分别放在不同的命名空间中,这是一个不好的想法吗?
使用命名空间:
//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();
};
}
另外,我也可以使用长名称:
class sparse_matrix
...
using namespace *;
吗?如果答案是否定的,那么这个做法就不是很安全。我建议直接使用完整名称,反正也不长。 - DeiDeidense::matrix
和sparse::matrix
比dense_matrix
和sparse_matrix
更长。 - Eli Sadoffusing namespace *;
。但我猜这种情况可能会发生...... - throw_away_account