calling another function within a function isnot working
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: calling another function within a function isnot working

  1. #1
    Join Date
    Feb 2013
    Posts
    36

    calling another function within a function isnot working

    I have two functions bool check_key(string cKey, string eKey) and bool check_digit(char digit1, char digit2), and I have declared both of them globally (is this the right terminology?) right after the "using namespace std;" and right before the "int main(){".

    In the first one, I called the second one . But it is giving me the error: "no match for call to `(std::string) (int&)' ".

    I am not sure how to fix this.


    Code:
    bool check_key(string cKey, string eKey)
    {
         if(cKey!="" && eKey=="") return false;
         if(cKey=="" && eKey=="") return true;
         if(cKey=="" && eKey!="") return true;
         if(cKey.length()!= eKey.length()) return false;
         
         bool flag=true;
         bool one_digit_wrong=false;
         
         for(int i=0;i<cKey.length();i++)
         {
                 if(cKey[i]!=eKey[i])
                 {
                                     if(!one_digit_wrong)
                                     {
                                                         flag=flag && check_digit(cKey[i],eKey(i));  //ERROR OCCURS HERE
                                                         one_digit_wrong=true;
                                     }
                                     else return false;
                 }
         }
         return flag;
    }
    
    bool check_digit(char digit1, char digit2)
    {
         int num = atoi(&digit1);
         string allowed = allowed_errors[num-1];
         
         for(int i=0; i<allowed.length();i++)
         {
                 if(digit2==allowed[i]) return true;
         }
         return false;
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,097

    Re: calling another function within a function isnot working

    flag=flag && check_digit(cKey[i],eKey(i));

    See anything different between the first argument and the second?

  3. #3
    Join Date
    Feb 2013
    Posts
    36

    Re: calling another function within a function isnot working

    Never mind! found the error!! I needed to change the () into a [] in eKey(i), because eKey is not a function .

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center