如何为Borland编译器重写C++模板代码

3
我正在尝试使用Borland的32位编译器编译MySql++。这个编译器以某些模板语法存在问题而闻名。由于clang编译器正在取代它,因此该编译器几乎已经过时。
但是,如果以下代码可以改为可编译版本,将节省时间。
编译器错误发生在以下行:
template <> MYSQLPP_EXPORT bool String::conv(bool) const;

编译器错误为:
[bcc32错误] mystring.h(726): E2506“String::conv(Type) const”的显式特化存在歧义:必须指定模板参数 完整的解析器上下文 transaction.cpp(32): #include lib\query.h query.h(37): #include lib\result.h result.h(40): #include lib\row.h row.h(33): #include lib\mystring.h mystring.h(46): 命名空间mysqlpp String是自定义字符串类,conv()函数是String类中的内联模板函数。
/// \brief Template for converting the column data to most any
/// numeric data type.
template <class Type>
Type conv(Type) const
{
    // Conversions are done using one of double/long/ulong/llong/ullong
    // so we call a helper function to do the work using that type.
    // This reduces the amount of template code instantiated.
    typedef typename detail::conv_promotion<Type>::type conv_type;
    return do_conv<conv_type>(typeid(Type).name());
}

我尝试了各种修改,但都没有成功。


你尝试过这些建议吗?:http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devwin32/compile_errambigtspec_xml.html - mike
2
template <> MYSQLPP_EXPORT bool String::conv<bool>(bool) const; 这段代码能正常工作吗? - NathanOliver
谢谢NathanOliver。那个完美地解决了问题!我怎样才能把你的评论设为正确答案? - Totte Karlsson
Mike,我看了那个Embarcadero的帮助文档。我感到困惑的是它只给出了一半的答案,就是说foo<int>而不是完整的答案foo<int>(int)。对我来说并不明显。 - Totte Karlsson
@TotteKarlsson:“我怎样才能把你的评论设为正确答案?” - 你不能。你或者Nathan必须发布一个单独的答案(是的,你可以在自己的问题下发布自己的答案)。 - Remy Lebeau
1个回答

0

这个答案是由nathanoliver提供的

 template <> MYSQLPP_EXPORT bool String::conv<bool>(bool) const;

这让bcc32编译器保持沉默...!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接