2

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.

1
  • Are you having a problem with the function that the compiler chooses? Commented May 28, 2015 at 15:26

1 Answer 1

3

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...

Sign up to request clarification or add additional context in comments.

3 Comments

Actually, the functions have a parameter Edgehandle, which is causing the problem. You can see the signature for the functions at the link I provided. Const casting the parameter results in the same error. Also, they're functions, not methods, so it isn't being called on an object.
Well, how do they have a const specifier, then? I guess you should look at the answer again, it's the *this that should be const to call the const version, not the parameter.
That's true. It doesn't make sense... @BarisDemiray

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.