T
T
trubanenkoalex2021-11-14 21:03:35
C++ / C#
trubanenkoalex, 2021-11-14 21:03:35

How to do serialization and deserialization in c++?

In the Derived1, Derived2 and Derived3 classes, implement the Serialize and Deserialize virtual functions. The Serialize function must save all its data to the buffer specified in the function parameters. Deserialize must restore the object's data from the buffer specified in the function parameters.
In the Inter class, two virtual functions are added, in child classes they must implement these functions.
Below is an example of an abstract class and the simplest child class

class Inter  {
public:
  virtual void input() = 0;
  virtual void output() = 0;	
  virtual void serialize() = 0;
  virtual void deserialize() = 0;

};

#ifndef LANGUAGE
#define LANGUAGE
#include "student.h"

class ProgramLanguage :public Student {

private:
  char* lang_name;
public:

  virtual void input ();
  virtual void output();
  virtual void serialize();
  virtual void deserialize();
  ProgramLanguage(const ProgramLanguage&) { assert(false); }
  void operator=(const ProgramLanguage&) { assert(false); }
  ProgramLanguage(const char* lang_name);

  virtual ~ProgramLanguage();
};
#endif // !LANGUAGE

#include "language.h"

ProgramLanguage::ProgramLanguage(const char* lang_name){
  this->lang_name = new char[20];
  strcpy(this->lang_name, lang_name);
}

void ProgramLanguage::input() {

}

void ProgramLanguage::output() {
  Student::output();
  printf("Language name: %s\n", lang_name);
}

void ProgramLanguage::serialize(Archive& ar) {
   

}

void ProgramLanguage::deserialize() {

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2021-11-15
@SaNNy32

https://habr.com/ru/post/479462/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question