I am trying to get this to compile:
#include <algorithm>
#include <climits>
#include <iostream>
#include <iterator>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
bool isInterleave(string &s1, string &s2, string &s3) {
auto dfs = [&](int i, int j, int k) {
if (k > s3.length()) {
return true;
}
if (s1[i] == s3[k]) {
auto res = dfs(i + 1, j, k + 1);
}
};
dfs(0, 0);
}
I get an error:
x86-64 gcc 9.3
-pedantic -Wall -O2 -std=c++2a
Could not execute the program
Compiler returned: 1
Compiler stderr
<source>: In lambda function:
<source>:14:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | if (k > s3.length()) {
| ~~^~~~~~~~~~~~~
<source>:18:18: error: use of 'dfs' before deduction of 'auto'
18 | auto res = dfs(i + 1, j, k + 1);
| ^~~
<source>: In function 'bool isInterleave(std::string&, std::string&, std::string&)':
<source>:23:11: error: no match for call to '(isInterleave(std::string&, std::string&, std::string&)::<lambda(int, int, int)>) (int, int)'
23 | dfs(0, 0);
| ^
<source>:13:14: note: candidate: 'isInterleave(std::string&, std::string&, std::string&)::<lambda(int, int, int)>'
13 | auto dfs = [&](int i, int j, int k) {
| ^
<source>:13:14: note: candidate expects 3 arguments, 2 provided
<source>:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
24 | }
| ^
How do I fix this?