0

So I'm working on serialization (I have never done it before so this is a first for me) and what I have done is created a base class called serialisable that all my other classes that can serialize can inherent from:

#include <iostream>

class Serializable{

public:
    Serializable();
    virtual ~Serializable();

    virtual void serialize();
    virtual void deserialize();

};

I then have a class that inherits from it which is my AbstractChunk class:

#pragma once

#include <iostream>
#include <list>
#include <fstream>
#include "AbstractBlock.h"
#include "Serialisable.h"

using namespace std;

#ifndef ABSTRACTCHUNK_H
#define ABSTRACTCHUNK_H
class AbstractChunk: public Serializable{
public:
    AbstractChunk();
    AbstractChunk(int x, int y);
    ~AbstractChunk();
    virtual int getXpos();
    virtual int getYpos();
    virtual bool unload();
    void serialize();
    void deserialize();

private:
    list<AbstractBlock> blocks;
    int xpos;
    int ypos;
};

#endif

and then the .cpp for my AbstractChunk (I edited out all the non important stuff):

#include "AbstractChunk.h"


void AbstractChunk::serialize(){
    ofstream chunkFile;
    chunkFile.open("ChunkData/" + to_string(xpos) + "." + to_string(ypos) + ".chunk");
    if (!chunkFile.good())
        cout << "Problem Opening Chunk File" << xpos << "." << ypos << endl;
    chunkFile << "xpos:" << xpos << "\n";
    chunkFile << "ypos:" << ypos << "\n";
    chunkFile.close();
}

void AbstractChunk::deserialize(){

}

So where is this error coming from? It's a linker error however I didn't mess with the dependencies or the project setup at all, I have a feeling I'm doing something stupid as usual.

EDIT Here are the actual errors

Error   1   error LNK2019: unresolved external symbol "public: __thiscall Serializable::Serializable(void)" (??0Serializable@@QAE@XZ) referenced in function "public: __thiscall AbstractChunk::AbstractChunk(int,int)" (??0AbstractChunk@@QAE@HH@Z)    C:\Users\Magnus\Documents\Visual Studio 2013\Projects\Top Down Shooter\Top Down Shooter\AbstractChunk.obj   Top Down Shooter

Error   2   error LNK2019: unresolved external symbol "public: virtual __thiscall Serializable::~Serializable(void)" (??1Serializable@@UAE@XZ) referenced in function __unwindfunclet$??0AbstractChunk@@QAE@HH@Z$0  C:\Users\Magnus\Documents\Visual Studio 2013\Projects\Top Down Shooter\Top Down Shooter\AbstractChunk.obj   Top Down Shooter
MagnusCaligo
  • 707
  • 2
  • 8
  • 28

1 Answers1

0

You are not specifying the exact linking error but for sure you are missing some methods, you have declared:

class Serializable {
    ..
    virtual void serialize();
    virtual void deserialize();
}

as non pure virtual methods, and you are not implementing them. You should turn them to pure, since Serializable doesn't implement functionality but it's only an interface:

class Serializable {
    ..
    virtual void serialize() = 0;
    virtual void deserialize() = 0;
}
Jack
  • 131,802
  • 30
  • 241
  • 343
  • I tried that before (and I just did it again to see if it would fix it) and that still didn't fix the problem... I edited my question to include the two errors. I posted them at the end – MagnusCaligo Sep 03 '15 at 17:33
  • You haven't defined constructor and destructor but you have declared them, the `virtual` destructor is required for safety but it needs an implementation, eg `virtual ~Serializable() { }` while the constructor can be omitted entirely and let the compiler generate a default one (remove `Serializable()`. – Jack Sep 03 '15 at 17:37
  • That actually removed the second error thank you! But I'm still getting the first, any ideas how to fix that? – MagnusCaligo Sep 03 '15 at 17:41