I had a very stupid typo in my code...
is.read((char*)&this->id, sizeof(this-id));
missing >
character after this-
Interestingly sizeof(this - id)
returned 8!
What I think is... since this
is a pointer, doing subtraction on this
will result in another pointer that is off by value of id which can be anything depending on the value of id.
And... on 64 bit system, pointer is usually 8 bytes!
Am I correct? or missing something?
Below is the class I have.
class IndexItem : public Serializable {
public:
IndexItem(uint32_t id, std::streampos pos) :
id(id),
pos(pos)
{ }
uint32_t id;
std::streampos pos;
protected:
std::ostream& Serialize(std::ostream& os) const override {
os.write((char*)&this->id, sizeof(this->id));
os.write((char*)&this->pos, sizeof(this->pos));
return os;
}
std::istream& Deserialize(std::istream& is) override {
is.read((char*)&this->id, sizeof(this->id));
is.read((char*)&this->pos, sizeof(this->pos));
return is;
}
};