Originally Posted by
Salem
>int *mana;
Why is this a pointer, and not say std::vector<int>mana ?
Thanks, this is the problem if I delete Ar& mana, this code saves everything without a problem (expectof course value of *mana) :
Code:
string name;
cin >> name;
might *something = new might("MoreTries","You got more tries",12,10,50,100,30,4);
something->save(*something,name);
So the problem is serializing pointer.
Originally Posted by
Salem
Further,which member of the class tells you how many elements are allocatedto this pointer?
I've defined it in constructor,should have gived all the methods, here there are:
Code:
might::might(string id, string about, int magic, int endlevel, int cost, int upg, int upcost, int manacost){
name=id;
descripction=about;
level=1;
maxlevel=endlevel;
price=cost;
upgrade=upg;
upgradecost=upcost;
manaup=manacost;
mana= new int[maxlevel];
for(int a=0; a<maxlevel;a++){
mana[a]=magic+manaup*a;
}
}
might::~might(){
delete[] mana;
}
ostream& operator<<(ostream& os,const might& m){
os << m.name << " " <<m.descripction << " " << m.mana[m.level -1] <<" " << m.level << " " <<m.maxlevel << " " << m.price << " "<< m.upgrade << " " << m.upgradecost <<" " << m.manaup << endl;
return os;
}
So when I'm trying to save this with Ar & mana (same for *mana or vector<int> mana) it gives me error "left of '.serialize'must have class/struction/union ".
In tutorial there such example:
Code:
class bus_route
{
friend class boost::serialization::access;
bus_stop * stops[10];
template<classArchive>
void serialize(Archive & ar, const unsigned intversion)
{
ar & stops;
}
and I don't see any reson to serialize pointers in a special way, am I missing something, why its not working?
ps.
Originally Posted by
Salem
> int*mana;
Why is this a pointer, and not say std::vector<int>mana ?
If I normaly want to have an array in class should I use STL container rather than pointer?