CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    [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.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    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?
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: None of the 2 overloads could convert all the argument types

    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: None of the 2 overloads could convert all the argument types

    Poop.

    Cheers!
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured