【发布时间】:2011-06-14 12:55:37
【问题描述】:
在对这个问题进行了彻底的解释之后,我试图学习和采用复制交换习语:the Copy-Swap Idiom。
但我发现了一些我从未见过的代码:using std::swap; // allow ADL 在这个例子中
class dumb_array
{
public:
// ...
void swap(dumb_array& pOther) // nothrow
{
using std::swap; // allow ADL /* <===== THE LINE I DONT UNDERSTAND */
swap(mSize, pOther.mSize); // with the internal members swapped,
swap(mArray, pOther.mArray); // *this and pOther are effectively swapped
}
};
-
using std::swap;在函数实现的主体内部是什么意思? - ADL 是什么意思?
【问题讨论】:
-
MSalter's answer 恕我直言,显然是更好更全面的答案,因为他解释了 ADL(这是在此处执行
using的全部原因)。我认为您应该选择它作为解决方案。
标签: c++ stl std using argument-dependent-lookup