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

标签 c++ c++builder mysql++

我正在尝试使用 Borland 的 32 位编译器编译 MySql++。众所周知,该编译器在某些模板语法方面存在问题。编译器也几乎过时了,因为它正在被 clang 编译器取代。

但是,如果可以将以下代码修复为可编译版本,则可以节省时间。

编译器错误发生在以下行:

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

编译错误是:

[bcc32 Error] mystring.h(726): E2506 Explicit specialization of 'String::conv<Type>(Type) const' is ambiguous: must specify template arguments
Full parser context
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): namespace 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());
}

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

最佳答案

这个答案是nathanoliver给出的

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

这会使 bcc32 编译器静音...!

关于c++ - 如何为 Borland 编译器重写 C++ 模板代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39665433/

相关文章:

c++ - 什么是 "Argument-Dependent Lookup"(又名 ADL,或 "Koenig Lookup")?

c++ - 使用 mysql++ 构建应用程序时找不到 mysql_version.h

mysql - 无法编译 MySQL++

linux - 升级 GCC 后 MySQL++ 库不工作

c++ - 读取原始数据文件,在 Matlab 和 C++ 中获取不同的值

c++ - 关于 char* 和 char[] 基础知识的问题

delphi - 将 Delphi 转换为 Borland C++ 构建器

c++ - 从 C 中的结构检索值时出现编译错误

c++ - 为什么 malloc() 基于链表?

C++:使用owl重新编译旧代码