Код: Выделить всё
f2Код: Выделить всё
f1#include
struct C {
float f1 = 0.0f; // Lots of members like this which I don't want to copy manually
float f2 = 0.0f; // In actual code dynamically allocated memory that needs deep copy
C(float f1 = 0.0f, float f2 = 0.0f) : f1(f1), f2(f2) {}
C(const C& other_obj)
: f1(other_obj.f1) // (1) I'd like to avoid this for many members
{ f2 = 2.0f * other_obj.f2; }
C& operator = (const C& other_obj) {
f1 = other_obj.f1; // (2) I'd like to avoid this for many members
f2 = 2.0f * other_obj.f2;
return *this;
}
};
int main()
{
C o1( 1.0f, 2.0f);
C o2(o1);
C o3;
o3 = o1;
std::cout
Подробнее здесь: https://stackoverflow.com/questions/796 ... t-operator
Мобильная версия