Domyślny konstruktor kopiujący w obliczu tablic

1

Siemka programy.
Mam pytanie czysto teoretyczne, związane z działaniem domyślnego konstruktora kopiującego (jak i operatora przypisania) w przypadku tablic:

#include <iostream>
#include <cstring>
using namespace std;

class test{
private:
    char tutej[20];
public:
    test(const char * s) {strcpy(tutej, s);}
    void show() {cout << tutej << endl;}
};

int main()
{
    test c1("hehe");
    c1.show();
    test c2=c1;
    c2.show();
    return 0;
}

Jak wiadomo przypisanie tablicy do innej tablicy jest niemożliwe, więc jak wykonuje to owy konstruktor? :p
P.S jeśli jest jakiś inny sposób przypisania znaków do tablicy zamiast funkcji strcpy, to też warto by było się dowiedzieć :p

2

jeśli jest jakiś inny sposób przypisania znaków do tablicy zamiast funkcji strcpy, to też warto by było się dowiedzieć

http://en.cppreference.com/w/cpp/string/byte/memcpy

Zastosuj się do zasady:

http://en.cppreference.com/w/cpp/language/rule_of_three

3

https://stackoverflow.com/a/4164318/1387438

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:

  • if the subobject is of class type, the copy constructor for the class is used;
  • if the subobject is an array, each element is copied, in the manner appropriate to the element type;
  • if the subobject is of scalar type, the built-in assignment operator is used.

Copy assignment:

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

  • if the subobject is of class type, the copy assignment operator for the class is used (as if by explicit qualification; that is, ignoring any possible virtual overriding functions in more derived classes);
  • if the subobject is an array, each element is assigned, in the manner appropriate to the element type;
  • if the subobject is of scalar type, the built-in assignment operator is used.
0

Jeżeli Ci z tymi charami nie działa to zrób to na stringu. Wtedy nawet nie trzeba robić strcpy.

1 użytkowników online, w tym zalogowanych: 0, gości: 1