Jump to content


Photo

question for c++ gurus (or not)


  • Please log in to reply
3 replies to this topic

#1 HMart

HMart

    Advanced Member

  • Member
  • PipPipPip
  • 708 posts

Posted 07 April 2018 - 07:28 PM

I have two overloaded functions in my class, for example:
 
virtual void  Foo(const idvec3 &parm1, const idAxis &parm2){}
 
virtual void  Foo(const idvec3 &parm1, const idAxis &parm2, const int parm3 = 0 ){}
 
But visual studio gives me a error of :  
 

Ambiguous call to overloaded function

 

How would you guys solve this?

What i did was call the second function another name for now, but would like to know if this has a solution.

Thanks in advance.

 

edit: changed some int's to the real types i'm using because that could be important for the problem solution. 


Edited by HMart, 07 April 2018 - 07:37 PM.


#2 Abusimplea

Abusimplea

    Member

  • Member
  • PipPip
  • 471 posts

Posted 07 April 2018 - 10:51 PM

Not a C++ coder, but might help to remove the default value from the third argument. I too would expect the two signatures to be ambiguous for calls with only two arguments.



#3 gnartsch

gnartsch

    Member

  • Member
  • PipPip
  • 486 posts

Posted 08 April 2018 - 02:24 AM

Abusimplea is right.
Basicly the compiler doesn't get what function it should use if you were calling method Foo with just two arguments.
It would not know whether to call the first variant or the second one (with default argument). That setup just doesn't make any sense at all.

 

Either go with

virtual void  Foo(const idvec3 &parm1, const idAxis &parm2){}
virtual void  Foo(const idvec3 &parm1, const idAxis &parm2, const int parm3){}

or just

virtual void  Foo(const idvec3 &parm1, const idAxis &parm2, const int parm3 = 0 ){}

Edited by gnartsch, 08 April 2018 - 02:25 AM.


#4 HMart

HMart

    Advanced Member

  • Member
  • PipPipPip
  • 708 posts

Posted 08 April 2018 - 06:59 AM

Oh shoot, sorry for the stupidity. :P   

 

still learning this stuff... :)

 

 

CMlZon5UkAA4T6H.png


Edited by HMart, 08 April 2018 - 07:17 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users