Answer:
The function in C++ is as follows
int chkInd(string str1, string str2){    
int lenstr1=0;
while(str1[lenstr1] != '\0'){  lenstr1++;  }
int index = 0; int retIndex=0;
for(int i=lenstr1-1;i>=0; i--){
    while (str2[index] != '\0'){
        if (str1[i] == str2[index]){
            retIndex=1;
            break;         }
        else{   retIndex=0;      }
   index++;    }
   if (retIndex == 0){   return i;   }else{return -1;}}
}
Explanation:
This defines the function
int chkInd(string str1, string str2){    
First, the length of str1 is initialized to 0
int lenstr1=0;
The following loop then calculates the length of str1
while(str1[lenstr1] != '\0'){  lenstr1++;  }
This initializes the current index and the returned index to 0
int index = 0; int retIndex=0;
This iterates through str1
for(int i=lenstr1-1;i>=0; i--){
This loop is repeated while there are characters in str2
    while (str2[index] != '\0'){
If current element of str2 and str1 are the same
        if (str1[i] == str2[index]){
Set the returned index to 1
            retIndex=1;
Then exit the loop
            break;         }
If otherwise, set the returned index to 0
        else{   retIndex=0;      }
Increase index by 1
   index++;    }
This returns the calculated returned index; if no matching is found, it returns -1
   if (retIndex == 0){   return i;   }else{return -1;}}
}