lundi 15 janvier 2018

What is the best way to implement a read and write of a struct when you know the struct will change in the future?

if I have a struct A that I know is not yet completely defined but I know that 'a' and 'b' are members of it and I need to write a function that reads and xml that populates it and writes it to an xml as it is now.

How can I write the read and write methods so that if someone in the future needs to add a member to struct A I can help him get an error saying that they also need to implement corresponding read and write that supports the extra member function?

struct A
{
  string a, b;
}

void read(A&);
void write(A&);

// in the future
// A becomes 
struct A
{
 string a, b, c;
}

void read(A&); // should give a useful error saying the read is outdated
void write(A&);

Aucun commentaire:

Enregistrer un commentaire