I have an abstract class for Serializing data as follows
template<class T>
class Serialize{
public:
virtual string serialize() = 0;
virtual T deSerialize(string value) = 0;
}
I also have a data model a follows
class PersonModel: public Serialize<PersonModel> {
...
public:
...
string serialize() { return "The serialized form";}
T deSerialize(string value) {return PersonModel();}
}
Now I have a generic context class as follows:
template<class T>
class DC{
private:
vector<T> data;
public:
vector<string> read(){
for each(auto i in data){
Serialize<T> *getSerializedData = dynamic_cast<Serialize<T>*>(i);
}
}
C++ showing the following error for the above cast:
Error C2682 cannot use 'dynamic_cast' to convert from 'PersonModel' to '
Serialize<PersonModel> *
'
How to work this around?