error C2668: ambiguous call to overloaded function
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: error C2668: ambiguous call to overloaded function

  1. #1
    Join Date
    Jun 2009

    error C2668: ambiguous call to overloaded function

    I am trying to build this in studio 2005, and getting the following error:
    error C2668: 'compare_string' : ambiguous call to overloaded function

    I am still learning C++, and dont understand the corrections and help others have provided here and other sites for this error. Any help would be great!

    From what i can tell, the error occurs in the ContainsSequence function, when it calls the compare_string function


    #include "stdafx.h"

    using std::string;

    static char SubKeyPath[]=REG_CONFIG_PATH;

    int compare_string(const std::string & s1, const std::string& s2)
    std::string::const_iterator it1=s1.begin();
    std::string::const_iterator it2=s2.begin();

    //stop when either string's end has been reached
    while ( (it1!=s1.end()) && (it2!=s2.end()) )
    if(::toupper(*it1) != ::toupper(*it2)) // letters differ?
    // return -1 to indicate smaller than, 1 otherwise
    return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1;
    //proceed to the next character in each string
    size_t size1=s1.size(), size2=s2.size();// cache lengths
    //return -1,0 or 1 according to strings' lengths
    if (size1==size2)
    return 0;
    return (size1<size2) ? -1 : 1;

    Function: ContainsSequence
    Purpose: Returns true if the password contains a common keyboard sequence
    or the reverse of a common keyboard sequence
    Notes: this may be obsolete if we just include these sequences in our dictionary

    bool ContainsSequence(const char *password, const char *reversepassword) {

    //array of keyboard sequences
    static char *sequence_array[] = {

    //number of elements in our array
    int array_count = sizeof(sequence_array)/sizeof(char *);

    bool val;
    val = false;

    //loop through these sequences and see if they're anywhere in
    //our password
    for (int z=0;z<array_count; z++) {

    //check forward and reverse
    //if (strstr(password,sequence_array[z]) || strstr(reversepassword,sequence_array[z])) {
    //if (((compare_string(password,sequence_array[z]))==0) || ((compare_string(reversepassword,sequence_array[z]))==0)) {
    if ((compare_string(password,sequence_array[z]))==0) {

    val = true;

    return val;


    Function: checkForSequences
    Purpose: Returns true or false depending on whether or not we want
    to check for keyboard sequences using ContainsSequences

    bool checkForSequences()
    HKEY hConfig;
    DWORD dwType, dwLen, checkSequences;
    checkSequences = NULL;
    bool bVal;
    bVal = true;

    LONG regOpenStatus = ERROR_SUCCESS;

    regOpenStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,SubKeyPath,0,KEY_QUERY_VALUE,&hConfig);

    if (regOpenStatus == ERROR_SUCCESS) {

    // returns the correct dwLen value
    RegQueryValueEx(hConfig,CHECK_SEQUENCES_REG_NAME, NULL, &dwType,NULL, &dwLen);

    // now call it again to get the DWORD value
    if (RegQueryValueEx(hConfig,CHECK_SEQUENCES_REG_NAME, NULL, &dwType,(LPBYTE)&checkSequences, &dwLen) == ERROR_SUCCESS) {

    if (dwType == REG_DWORD) {

    if (checkSequences == 0) {
    bVal = false;



    return bVal;

  2. #2
    Join Date
    Jul 2005

    Re: error C2668: ambiguous call to overloaded function

    Please put [code][/code] tags around your code and make sure it's indented correctly. It's very hard to read now.
    Also, are there more lines below the compiler error? I would expect something like "could be ... or ... or ...".
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Fairfax, VA

    Re: error C2668: ambiguous call to overloaded function

    Your code is a rather odd mishmash of C and C++ styles. If you want a case-invariant compare in the C style, use stricmp() or write it if your compiler doesn't have that one (not all of them do).

    If you want to use C++ style, use std::strings everywhere rather than relying on char*s, and use std::transform to create lowercase versions.

Posting Permissions

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

Azure Activities Information Page

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


HTML5 Development Center