c++ - 错误: More than one instance of overloaded function matches the argument list

标签 c++ visual-studio overloading

我正在使用OpenMesh库,他们提供了两个函数edge(),它们仅在常量上有所不同。 Const edge()edge() 。有什么方法可以向编译器指定我要使用哪个函数?

看起来这应该是与库不同的设计决策,但不确定我是否可以改变它,所以如果我可以做些什么来在编译器中绕过它......我正在使用 VS2013。

我意识到人们已经提出了有关此错误的问题,但我还没有发现任何对此类情况有帮助的内容。

最佳答案

我假设你的情况是这样的:你有一个

class aclass
{
  edge_t edge(void) ;
  edge_t edge(void) const ;
} ;

如果您有 const 对象,则将调用第二个版本,否则将调用非 const 对象。所以如果你有

const aclass x ;
aclass y ;

x.edge() ; // calls the second
y.edge() ; calls the first
const_cast<const aclass &>(y).edge() ; // calls the const (second) 

后者是一种(相对)安全的作弊方式......

关于c++ - 错误: More than one instance of overloaded function matches the argument list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30510573/

相关文章:

c++ - C++ Eigen 库中用于设置 vector/矩阵的未知错误

c++ - 带有 VideoCapture 的 OpenCV "stuck"帧

c++ - 上下文对象的同步

javascript - 我可以在调试时只输入 "step over"jQuery 代码吗?

c++使用int和char *重载构造函数

C++ 错误 : terminate called after throwing an instance of 'std::bad_alloc'

c++ - ATL 安全更新破坏了 DLL 的兼容性,具体取决于旧版本

vb.net - 我如何检查vb.net中的datagridview列中的复选框是否被选中

javascript - 为什么可以在 javascript 中减去 Date 对象?是否有任何形式的运算符重载?

haskell - 类型类和重载,有什么联系?