Ren
Ren

Reputation: 463

Error: More than one instance of overloaded function matches the argument list

I'm working with the library OpenMesh, and they offer two functions edge(), which only differ in their constness. Const edge() vs edge(). Is there any way to specify to the compiler which function I want to use?

It seems like this should have been a different design decision from the library, but not sure that I can alter that, so if there's anything I can do to bypass it in the compiler...I'm using VS2013.

I realize that people have already asked questions about this error, but I haven't found anything helpful for this type of case.

Upvotes: 2

Views: 1529

Answers (1)

marom
marom

Reputation: 5230

I assume you situation is like this: you have a

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

The second version will be called if you have a const object, the non const otherwise. So if you have

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) 

The latter is a (relatively) safe way to cheat...

Upvotes: 3

Related Questions