我正在做一些关于 mysql C API 封装的练习。当我决定编写这样的 sql 时。
template<class T> C_SQL& operator%(const char* txt)...;
template<class T> C_SQL& operator%(T& t)...;
template<class T> C_SQL& operator,(T& t)...;
Int kk;
Small jj;
C_SQL sql;
sql % "insert into test_table (tiny_col,short_col) values (" % kk , jj % ")" ;
我的计划是通过重载三个运算符,可以得到这样的sql文本:
"insert into test_table (tiny_col,short_col) values (? , ?)" ,
并创建一些绑定变量,这些变量引用客户端变量的地址,如 kk、jj。
我的问题是:
由于 operator%() 的优先级高于 operator,() ,jj 坚持使用 ")" % 并且编译错误抱怨类 Small 没有 operator%。
怎么做 ?让 char*、kk、jj 和 char* 通过写命令进入 sql 对象。