C++ application code was compiling fine with GCC 4.1. Now i upgraded the GCC version to 4.4X and i am getting an error.
error: declaration of ‘data’ as array of references
CODE:
inline std::string base64_encode(const std::vector< unsigned char >& data)
{
if (data.empty())
{
return "";
}
using namespace boost::archive::iterators;
typedef base64_from_binary<
transform_width< const unsigned char*, 6, 8> > base64_enc;
std::string result(base64_enc(&data[0]),
base64_enc(&data[0] + data.size()));
static const std::string base64_padding[] = { "", "==", "=" };
result.append(base64_padding[data.size() % 3]);
return result;
}
I read few answers and came to know that this doesn't comply with vexing parse rule.
One possible solution is to enclose (&data)[0] or std::string result({base64_enc(&data[0]}), base64_enc(&data[0] + data.size();
std::string result(base64_enc(&data[0]),
base64_enc(&data[0] + data.size()));
Compiler should not consider this line as a function declaration. How do i apply the proper grammar in this case ?