You are right about passing by reference. That's the way I had it initially but tried passing by value when I couldn't find any fix for this problem. I forgot to change it back.
I do have a #include to BinStreamIn.h in DataStreamReader.h
Code:
#include "BinStreamIn.h"
class DataStreamReader
{
public:
int GetValues(BinStreamIn &dataFile, VALUE_TYPE values[]);
};
Code:
#include "DataStreamReader.h"
int DataStreamReader::GetValues(BinStreamIn &dataFile, VALUE_TYPE values[])
{
// Local Variables
unsigned int counter = 0;
while(counter < MAX_VALS)
{
dataFile >> values[counter];
counter++;
cout << "#vals = " << counter - 1 << " value read = " << (VALUE_TYPE)values[counter - 1] << endl;
}
return counter;
} // end function GetValues
Here's BitStreamIn.h
Code:
#include "..\FEP\fep.h"
#include <fstream>
using namespace std;
class BinStreamIn : public ifstream
{
public:
BinStreamIn( const char *inputFileName );
void ReadBytes(void *inputBytes, int numOfBytesToInput);
template <class T> BinStreamIn & operator>> (T &inputValue);
}; // end class BinStreamIn
////////////////////////////////////////////////////////////////////////////////
//
// Function Name : ReadBytes
//
////////////////////////////////////////////////////////////////////////////////
void BinStreamIn::ReadBytes(void *inputBytes, int numOfBytesToInput)
{
// Local Variables
bool somethingIsWrongWithTheVoidPointer = !inputBytes;
bool invalidNumOfBytesProvided = (numOfBytesToInput <= 0);
if (somethingIsWrongWithTheVoidPointer || invalidNumOfBytesProvided)
{
return;
} // end if
else
{
read((char *)inputBytes, numOfBytesToInput);
} // end else
} // end function BinStreamIn::ReadBytes
////////////////////////////////////////////////////////////////////////////////
//
// Function Name : operator>>
//
////////////////////////////////////////////////////////////////////////////////
template <class T> BinStreamIn & BinStreamIn::operator>> (T &inputValue)
{
BinStreamIn::ReadBytes( &inputValue, sizeof(inputValue) );
return *this;
}; // end function BinStreamIn::operator>>
I did find that if I use the alternate method of calling the overloaded >> operator like this:
Code:
dataFile.operator >>(values[counter]);
that I get a different error.
Code:
DataStreamReader.cpp(28) : error C2893: Failed to specialize function template 'class BinStreamIn &__thiscall BinStreamIn::operator >>(T &)'
With the following template arguments:
'unsigned short'
Hopefully that's enough code to spot a problem.