我试着学习并采用复制交换惯用法,参考了这个问题中详细的解释: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 是什么意思?
using
的整个原因)。我认为你应该选择那个作为解决方案。 - Cheers and hth. - Alf