我正在尝试使用MSVC10编译这个库,但是这个函数让我很头疼:
/*! \brief Read bytes from a \c std::istream
\param is The stream to be read.
\param data A pointer to a location to store the bytes.
\param size The number of bytes to be read.
*/
void _read(std::istream &is, unsigned char *data, int size)
{
for (int i=0; i < size ; ++i )
is.get(static_cast<char>(data[i]));
}
错误 C2664:“std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem &)”:无法将参数 1 从“char”转换为“char &”
原始代码使用 static_cast,我尝试使用其他地方建议的 reinterpret_cast,但仍然失败:
错误 C2440:“reinterpret_cast”:无法将类型为“unsigned char”的表达式转换为类型“char”
该库带有unix makefiles。如何解决这个编译错误?
static_cast
将一个值转换为rvalue,你不能将rvalue传递给期望lvalue引用的函数。 - Seth Carnegiestatic_cast
转换成不太安全的reinterpret_cast
? - David Rodríguez - dribeas