[Development] Copying a struct the easy (perhaps too easy) way
Henry Skoglund
henry at tungware.se
Sat Sep 16 01:41:34 CEST 2023
Hi, just got the need to copy a struct so I started doing it the hard
way (i.e. member by member) but on a lark I tried a simple copy from
*this, say like this:
struct S
{
int i;
QString s;
QDate d;
QStringList sl;
S clone() { return *this; }
};
S a;
S b = a.clone();
it seems to work like a charm (6.5.2 on Linux and the Mac. 5.15.2 on
Windows) but my question is if it's kosher?
I have bad memories from my MFC days in the previous century doing this
simple cloning but maybe it's considered good code now...
Rgrds Henry
More information about the Development
mailing list