List:MySQL++« Previous MessageNext Message »
From:Mickael Wolff Date:August 16 2012 1:16pm
Subject:Re: Problem with types in sql_types.h
View as plain text  
On 16/08/2012 13:33, Warren Young wrote:

> 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.

   Yes, and it finds two operator= and can't choose the right one :) The 
guilt is the cast operator in class String. My first thought was the 
ctor that takes a null object that is not declared explicit. But make it 
explicit doesn't fix the annoyance. Then, I crawl the code for a cast 
operator that raise hell:

== 8< == /usr/include/mysql++/mystring.h ==
	template <class T, class B>
	operator Null<T, B>() const { return conv(Null<T, B>()); }
== >8 ==

   Because of this defined cast operator, GCC know it can cast the 
object, and use both Null<>::operator. As a general rule of thumb, we 
should never define cast operator to the world. It leads to headaches 
:'( It's why std::strstream doesn't provides a cas operator to a 
std::string, neither boost::format does it. They provides a member 
function str() that returns the std::string.

> 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.)

To rid off this kind of problems, I guess removing all the cast operator 
is a good start, but it will eventually breaks the ABI :-/


-- 
Mickaël Wolff aka Lupus Michaelis
Racine <http://lupusmic.org>
Blog   <http://blog.lupusmic.org>
Thread
Problem with types in sql_types.hJoseph Hesse16 Aug
  • Re: Problem with types in sql_types.hWarren Young16 Aug
    • Re: Problem with types in sql_types.hMickael Wolff16 Aug
      • Re: Problem with types in sql_types.hMickael Wolff17 Aug