On 8/16/2012 4:03 AM, Joseph Hesse wrote:
> x = res[i]["Cost"]; // THIS LINE WON'T COMPILE
In future, please include compiler error messages with reporting such
problems. We don't all use the same toolchains or platforms. Even if
we did happen to in this case, that doesn't mean your test case is
enough to match your symptom in all cases.
I assume you are getting an ambiguous operator error?
If so, the simple fix is:
mysqlpp::sql_double_null x = res[i]["Cost"];
That is, don't separate the declaration and assignment.
Why does this work? Because it causes a call to a Null<T,B>
constructor, instead of Null<T,B>::operator=().
I'm not sure why this doesn't work just as well, though:
mysqlpp::sql_double_null x(res[i]["Cost"]);
That should also call a ctor instead of an operator, but apparently GCC
thinks it should be calling a different one in that case.
I'm also mystified why operator=() doesn't work in the first place.
Null<T,B> defines the same set of operator=() as it defines ctors. If
the compiler can find a suitable ctor to call, it should be able to find
a suitable operator.
This feels like one of those weird C++ corner cases, where you have to
be a language lawyer to understand what declaration you're supposed to
provide so the compiler doesn't run into ambiguous call situations.
If anyone can figure it out and provide a patch, it'll likely go in
without much fuss, Null being a template and all. (Template changes
don't affect the library ABI.)