写了7,8年的c++的代码,第一次在三木运算符上遇到坑。
pstrValue = ProbeBind(pstrValue) ? ParseBind(pstrValue) : pstrValue;
ParseBind 返回值的类型与pstrValue是不一样的类型的,结果发现在运算的时候,不管ProbeBind函数返回true或者false,pstrValue会被隐私转换到ParseBind的返回值类型上,于是就会有临时对象产生出现了bug。
通过这种方式解决以下问题:
pstrValue = ProbeBind(pstrValue) ? decltype(pstrValue)(ParseBind(pstrValue)) : pstrValue;