我厌倦了编写 shared_ptr<>,它极大地延长了代码行。有什么理由不这样做吗?
最佳答案
为什么要使用宏?这样的机制已经存在:
typedef boost::shared_ptr<some_longer_name_omg_help> pointer_type;
pointer_type p; // phew
如果您要询问史蒂夫在评论中的建议,您可以尝试:
template <typename T>
struct sp
{
typedef boost::shared_ptr<T> type;
};
typedef sp<some_longer_name_omg_help>::type pointer_type;
但我不知道它是否更短。
老实说,我认为您使用宏是懒惰的表现。 boost::shared_ptr
在几乎所有合理的“冗长”度量中,一点都不冗长。你所做的只是破坏可读性。
关于c++ - 使用宏来缩写长篇大论的 boost 模板名称是一种不好的做法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2430322/