0

I have a small question, if I have an class with members, for example like this

class CSelectPlayerData : public SqlQuery
{
public:
    BYTE m_Member;
    WORD m_Member2;

    Load_Data(CSelectPlayerData, "SELECT Member, Member2 FROM TABLE);
    MAKE_PARAM(m_Member, m_Member2);
}

What this code does, is that it loads data from sql table, and assigns them to Member and Member2. My question now is, if I use the query, and do something like this :

INIT_QUERY(db, CSelectPlayerData) //this also executes the LoadData etc (it's macro)
pPlayer->m_Member = query->m_Member;
...

and then make an separate class, CPlayer

CPlayer Player;

which has the same parameters (Member, Member2), can I somehow memcpy the values from the query's class to the player, so I don't have to do the

pPlayer->m_... = query->m_...

I know it's not really that useful, but it kinda would be just for my additional knowledge. Thanks for answers.

Martin Prince
  • 139
  • 1
  • 5
  • 1
    [Get a few good books to read](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282), and learn about *copy-construction* or *conversion constructors*. – Some programmer dude Jun 17 '18 at 10:15
  • You can make CPlayer to take these 2 arguments when the class is constructed. – Killzone Kid Jun 17 '18 at 11:15

1 Answers1

2

memcpy is safe on any type that has the trait std::is_trivially_copyable.

However many classes are not trivially copyable in which case you should use a copy constructor.

doron
  • 27,972
  • 12
  • 65
  • 103