我正在尝试将我的代码从 VS2008 移植到 VS2013,但我遇到了一些 std::bind 错误。错误说错误 C2668:'bind':对重载函数的模糊调用。这是一些代码:
// Relevant prototypes:
class CLineaPlanta:public SomeBase { /*...*/ };
int SomeBase::TipoLinea()const;
void SomeBase::TipoLinea(int val);
// function paramater: const std::shared_ptr<CLineaPlanta>& lineasBuscar
// function parameter: int tipoLinea;
std::shared_ptr<CLineaPlanta> lineas;
std::remove_copy_if(lineasBuscar.begin(), lineasBuscar.end(),
std::back_inserter(lineas),
bind(std::not_equal_to<int>(), bind(&CLineaPlanta::TipoLinea, _1), tipoLinea));
此代码在 Visual Studio 2008 中有效,但在 Visual Studio 2013 中给出了上述错误。
显然,编译器很难确定我要调用哪个版本的 TipoLinea()。如果我将 getter 版本重命名为 getTipoLinea,错误就会消失。
以防万一它是相关的, SomeBase 是非抽象的,并且派生自 CObject (不确定为什么)和与这部分代码无关的接口。
谁能解释为什么VS2008对此没有任何问题以及如何防止它(当然,除了重命名函数之外)?