如何C ++的阵列成员拷贝控制功能处理? [英] How are C++ array members handled in copy control functions?

查看:136
本文介绍了如何C ++的阵列成员拷贝控制功能处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想知道很长一段时间。看看下面的例子:

This is something I have wondered for a long time. Take the following example:

struct matrix
{
    float data[16];
};

我知道什么是默认的构造函数和析构函数在这个具体的例子(没有)做些什么,而关于拷贝构造函数和拷贝赋值运算符?

I know what the default constructor and destructor do in this specific example (nothing), but what about the copy constructor and the copy assignment operator?

struct matrix
{
    float data[16];

    // automatically generated copy constructor
    matrix(const matrix& that) : // What happens here?
    {
        // (or here?)
    }

    // automatically generated copy assignment operator
    matrix& operator=(const matrix& that)
    {
        // What happens here?

        return *this;
    }
};

是否涉及的std ::复制的std :: uninitialized_copy 的memcpy memmove与还是什么?

推荐答案

这是什么标准12.8(复制类对象)说。拷贝构造:

This is what the standard says in 12.8 (Copying class objects). Copy construction:

每个子对象以适合其类型的方式复制:

Each subobject is copied in the manner appropriate to its type:


      
  • 如果子对象是类类型,该类的拷贝构造函数是用来;

  •   
  • 如果子对象是一个数组,每个元素被复制,在适当的元素类型的方式;

  •   
  • 如果子对象是标量型,内置赋值运算符时使用。

  •   

拷贝赋值:

每个子对象以适合其类型的方式分配的:

Each subobject is assigned in the manner appropriate to its type:


      
  • 如果子对象是类类型,该类的拷贝赋值运算符(好像被明确的资格,也就是忽略了更多的派生类的任何可能的虚拟压倒一切的功能);

  •   
  • 如果子对象是一个数组,每个元素被分配在适当的元素类型的方式;

  •   
  • 如果子对象是标量型,内置赋值运算符时使用。

  •   

这篇关于如何C ++的阵列成员拷贝控制功能处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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