I have written a C++ class which includes an ifstream as a member. However, when compiling the class, the following compilation error comes up:
Error 1 error C2248: 'std::basic_ifstream<_Elem,_Traits>::operator =' : cannot access private member declared in class 'std::basic_ifstream<_Elem,_Traits>' c:\path\to\project\parser\bitstreamreader.h 55
The error is said to occur on the last line, where the class declaration is terminated. I understand that streams cannot be copied, hence that the = operator is inaccessible. However, as you can see from the code below, all I am doing here is declaring the existence of an ifstream. Why should that trigger this error at all?
class BitstreamReader {
public:
BitstreamReader(std::string file_name);
BitstreamReader();
~BitstreamReader();
UINT8 ReadBit();
UINT32 ReadBits(UINT32 bits);
INT32 ReadSignedBits(UINT32 bits);
UINT8 ReadByte();
UINT32 NextBits(UINT32 bits);
UINT32 ByteAlignedNextBits(UINT32 bits);
UINT32 GetPerByteBitOffset();
BOOL ByteAligned();
VOID AlignToByte();
BOOL EndOfBitstream();
VOID OpenFile(std::string file_name);
std::ifstream BitstreamFile;
private:
VOID FillBuffer();
UINT32 BitstreamPointer;
UINT32 BitBuffer;
UINT8 BitBufferPointer;
UINT8 BitBufferSize;
};
I had at first declared the ifstream as a private member of this BistreamReader class. However, when the error occured I tried making it public to see if it made any difference. It did not.
This error is really vague. I have no idea what's causing it. I am not trying to use the = operator in any of the method implementations, either..
Here are the constructors (after trying out some of the solutions in other questions):
BitstreamReader::BitstreamReader() :
BitstreamFile("empty.dat", std::ios::in)
{
BitstreamPointer = 0;
FillBuffer();
BitBufferSize = sizeof(BitBuffer) * CHAR_BIT;
}
BitstreamReader::BitstreamReader(std::string file_name) :
BitstreamFile(file_name, std::ios::binary)
{
BitstreamPointer = 0;
FillBuffer();
BitBufferSize = sizeof(BitBuffer) * CHAR_BIT;
}