-
March 12th, 2009, 08:24 AM
#1
[RESOLVED] None of the 2 overloads could convert all the argument types
Hey.
Got a really stupid problem. I get the errors below from the first call below to set_from_slider_value. I tried casting the arguments to the parameters the function takes, but no cigar. I then created x and sv2, and passed 0 and 100 as min and max, and that worked...
Code:
void Board::Set_Computer_Delay(const Slider_Value& sv)
{
set_from_slider_value(sv, computer_delay, min_computer_delay, max_computer_delay);
int x = 0;
Slider_Value sv2(23, 34);
set_from_slider_value(sv2, x, 0, 100);
}
1>c:\documents and settings\bill\my documents\visual studio 2005\projects\checkers\checkers_sdl\checkers_sdl\board.cpp(1272) : error C2665: 'set_from_slider_value' : none of the 2 overloads could convert all the argument types
1> c:\documents and settings\bill\my documents\visual studio 2005\projects\checkers\checkers_sdl\checkers_sdl\slider_value.h(22): could be 'int &set_from_slider_value(const Slider_Value &,int &,int,int)'
1> while trying to match the argument list '(const Slider_Value, unsigned short, unsigned short, unsigned short)'
computer_delay, min_computer_delay and max_computer delay are declared as:
Code:
unsigned short min_computer_delay; // Minimum computer delay in milliseconds.
unsigned short max_computer_delay; // Maximum computer delay in milliseconds.
unsigned short computer_delay; // Seconds it takes for the computer to make a move.
The set_from_slider_value functions:
Code:
int& set_from_slider_value(const Slider_Value& sv, int& value, int min, int max);
// Exactly the same as above except doesn't clamp.
int& set_from_slider_value(const Slider_Value& sv, int& value, int max);
int& set_from_slider_value(const Slider_Value& sv, int& value, int min, int max)
{
if(sv.denominator == 0)
{
throw LRE_Exception("Tried to divide by zero in " + std::string(__FUNCTION__) + '.');
}
value = std::max(min, std::min(sv.numerator * max / sv.denominator, max));
return value;
}
int& set_from_slider_value(const Slider_Value& sv, int& value, int max)
{
if(sv.denominator == 0)
{
throw LRE_Exception("Tried to divide by zero in " + std::string(__FUNCTION__) + '.');
}
value = sv.numerator * max / sv.denominator;
return value;
}
Cheers.
-
March 12th, 2009, 08:33 AM
#2
Re: None of the 2 overloads could convert all the argument types
I think that the problem is that computer_delay is an unsigned short, but the corresponding parameter is an int&. Due to the non-const reference, a temporary cannot be created, so there is no match. A workaround could be to use a local int variable, then assign that int to computer_delay.
-
March 12th, 2009, 08:39 AM
#3
Re: None of the 2 overloads could convert all the argument types
What about implicit casting? Explicit casting? Can't you cast something to a reference?
-
March 12th, 2009, 08:44 AM
#4
Re: None of the 2 overloads could convert all the argument types
Originally Posted by Mybowlcut
What about implicit casting? Explicit casting? Can't you cast something to a reference?
No, since the cast would result in a temporary, and temporaries cannot be bound to non-const references. A local variable would effectively be a temporary anyway, albeit one whose lifetime has a larger scope.
-
March 12th, 2009, 09:01 AM
#5
Re: None of the 2 overloads could convert all the argument types
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|