On Jun 30, 2008, at 3:59 AM, Soul Boy wrote:
> Should I be able to do this ?:
> mysqlpp::Null<mysqlpp::sql_tinyint_unsigned> nullString;
> Test newRow (nullString, 1);
No, you can't, on purpose.
If it did compile, it wouldn't work sensibly, for a couple of reasons.
If we take your code literally -- as the compiler will -- nullString
isn't initialized. Therefore, nullString.data also has no value, so
newRow.A will get an undefined value.
If we instead assume that nullString *did* get initialized between
your two lines of code, your declaration says it could be a SQL null,
so you'd again get undefined in newRow.A.
It's easy to make the code compile:
Test newRow(nullString.data, 1);
But this only makes sense if you know in advance that nullString is
initialized with something other than SQL null. In that case, I
wonder why you are wrapping that data member in template Null to begin
You *can* do the inverse of what you asked:
Test2 newRow2(nullString, 1);
Conversion this direction works because it never loses data. It's
much the same thing as type promotion in C++: you can assign a char to
an int and always get sensible results.