Nov 4, 2009 at 8:52pm UTC
My lecturer wrote this code
1 2 3 4
class IOBuffer {
public :
virtual TPointer Read(fstream& fs) = 0;
};
Error `Read' declared as a `virtual' field. Expected `;' before '(' token, expected unqualified-id before '=' token .
What is going on here?
Last edited on Nov 4, 2009 at 8:54pm UTC
Nov 4, 2009 at 8:54pm UTC
It should work, do you have some other code with that?
Nov 4, 2009 at 9:00pm UTC
Here's a bit more of the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
class IOBuffer {
protected :
char Buffer[MAXBYTES];
TSize BufferSize;
TSize MaxBytes;
TSize NextByte;
int _Format;
public :
IOBuffer(): MaxBytes(MAXBYTES), BufferSize(0), NextByte(0){}
virtual TPointer Read(fstream& fs) = 0;
virtual TPointer Write(fstream& fs) const = 0;
virtual TSize Pack(const void * field, TSize size = -1) = 0;
virtual TSize UnPack(void * field, TSize size = -1) = 0;
virtual void Clear(void ) {BufferSize = NextByte = 0;}
virtual TSize Length(void ) const {return (BufferSize);}
void ResetB(void ) { // Resets NextByte
NextByte = 0;
return ;
}
int Format(void ) {return _Format;}
};
//IOBuffer <--->HD
class VarLenBuffer: public IOBuffer {
public :
virtual TPointer Read(fstream& fs);
virtual TPointer Write(fstream& fs) const ;
};
//This is implemented in a .cpp file
//there are many other methods like this
TPointer VarLenBuffer::Read(fstream& fs){
TPointer pos = fs.tellg();
Clear();
fs.read((char *)& BufferSize,sizeof (TSize));
fs.read(Buffer, BufferSize);
return pos;
}
Last edited on Nov 4, 2009 at 9:05pm UTC
Nov 4, 2009 at 9:03pm UTC
This is just a portion of the code. The code itself is way bigger.
TPointer was declared already in the beginning
1 2 3 4 5
typedef long TPointer;
typedef int TSize;
const int MAXBYTES = 1000;
const long PNULL = -1;
EDIT :(the message this was an answer to was deleted)
Last edited on Nov 4, 2009 at 9:06pm UTC
Nov 4, 2009 at 9:11pm UTC
I tried that in g++ 4.4 but it doesn't complain.
Which compiler / options are you using?
Do you get other error messages?
EDIT :(the message this was an answer to was deleted)
What?
[Edit]
Found the error. The code was missing this line
OK
Last edited on Nov 4, 2009 at 9:12pm UTC