template<class RECORD>
TPointer FileBuf<RECORD>::Read(RECORD& r, const TPointer pos) {
if (fs.is_open()){
if (pos != -1) fs.seekg(pos);
TPointer ret = (*Buffer).Read(fs); // <- Somehow ret is still unassigned
//TPointer is declared as typedef long TPointer;
//Buffer is a private attribute declared IOBuffer* Buffer
r.UnPack(Buffer); //unpack works properly and has nothing to do with ret
cout << "Ret = "<< ret<< endl; // This prints "Ret = " and not "Ret = 16"
return ret;
}
return -1;
}
//-------------------------------------------------------------
//The method below is located in the template class FixLenBuffer (a son class of IOBuffer)
TPointer FixLenBuffer::Read(fstream& fs){ //This method is virtual
TPointer pos = fs.tellg();
Clear();
BufferSize = RecordSize;
fs.read(Buffer, RecordSize);
cout << "Pos = " << pos << endl; // This prints "Pos = 16"
return pos; // Why the hell does this return not work?
}
Tell me if you need more information on any particular variable/class/Etc..
Thanks in advance!!
Actually, when executing the code, i can see on the screen
1 2
Pos = 16
Ret =
So, "pos" (the value to be returned in Read) is NOT undefined : I was able to print it on the screen ( Pos = 16. Yeah, i wrote the P in caps, but the variable is called pos). However, ret is undefined, and that makes no sense at all!, because
TPointer ret = (*Buffer).Read(fs); // <- Somehow ret is still unassigned
TPointer is declared as typedef long TPointer
EDIT: Bazzy, I'm running this on windows console, and since windows hides the errors in the console, I can see it displaying a window that says "p10.exe has had an error an had to be closed". The error occurs on this line
cout << "Ret = "<< ret<< endl;
The execution is aborted when accessing the variable ret.
Try running it through a debugger. If the program really does crap out when trying to access ret (it could be that it just dies before having a chance to completely flush the buffer), you have memory corruption.
Thanks helios. Yeah, it seems the problem is related to that.
When i do r.UnPack(Buffer); the memory goes nuts, and something weird happens to ret (...Curiously i thought UnPack was working properly).
It's very likely it has something to do with the amount of data I'm unpacking on the buffer.