Sorry for this basic question, not really related with Esenthel Engine, but maybe somebody from users could help me. Also sorry for my english.
Code:
Memc<CharBase *> Charbases;
[code]
struct CharBase
{
virtual Byte getType(){return CHR_BASE;}
}
struct Tower : CharBase
{
virtual Byte getType(){return CHR_TOWER;}
}
Code:
void CreateTowers()
{
FREP(22){
Tower t;
Charbases.New() = &t;
}
}
Code:
void compressData(File &f)
{
f.putInt(Charbases.elms());
REPA(Charbases)
{
f.putByte(Charbases[i]->[b]getType()[/b]); <-- this line crash program
Charbases[i]->compress(f);
}
}
Charbase[i]->anyfunc() would crash program, and I don't really know why. This probably some basic stuff I just forgot (I used to programing some time ago, but I had a long break)
(This pop up in debug mode: Unhandled exception at 0x00d59a81 in Server.exe: 0xC0000005: Access violation reading location 0xffffffff)
So, I try something like this
Code:
Memc<CharBase > Charbases;
Code:
struct CharBase
{
virtual Byte getType(){return CHR_BASE;}
}
struct Tower : CharBase
{
virtual Byte getType(){return CHR_TOWER;}
}
Code:
void CreateTowers()
{
FREP(22){
Tower t;
Charbases.New() = t;
}
}
Code:
void compressData(File &f)
{
f.putInt(Charbases.elms());
REPA(Charbases)
if(Tower *twr=CAST(Tower, &Charbases[i]))
{
f.putByte(twr->getType());
twr->compress(f);
}
}
but this time CAST always returning NULL (all elements in Charbase are CharBase type).
I'm sure there is easy way to fix one of above, but i can't figure it by myself. Please, don't laugh at me...