什么是`使用std :: swap`里面的类方法实现的意思? [英] what does `using std::swap` inside the body of a class method implementation mean?

查看:469
本文介绍了什么是`使用std :: swap`里面的类方法实现的意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天下午在做一些c ++练习,并试图学习并采用copy-swap惯用法对这个问题进行彻底的解释:复制交换习语

I was doing some c++ practicing this afternoon, and was trying to learn and adopt the copy-swap idiom following this thoroughfully explanation on this question: the Copy-Swap Idiom.

但我发现了一些从未见过的代码: using std :: swap; // allow ADL 在这个例子中

But I found some code I had never seen: using std::swap; // allow ADL in this example

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
    }
};




  1. 意味着
    在函数体内的
    实现?

  2. ADL是什么意思?

  1. what does using std::swap; mean inside the body of a function implementation ?
  2. what does ADL mean ?


推荐答案

使用关键字具有作用域效果。

The using keyword has scoped effect.

这意味着 std :: swap 使用关键字的范围内,可以将称为 swap

这篇关于什么是`使用std :: swap`里面的类方法实现的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆