Ссылка < /p>
Мой тестовый код ниже. Насколько я понимаю, мое использование AUTO в контексте, как указано в вышеуказанной ссылке для действительного кода C ++. Тем не менее, я все еще получаю ошибку < /p>
error: expected primary-expression before ‘auto’
if((auto pos = s2.find(c)) != -1)
< /code>
Чего мне не хватает? < /p>
tia < /p>
vinod < /p>
#include
#include
#include
#include
using std::string;
using std::set;
using std::for_each;
using std::cout;
using std::endl;
void compare(const string& s1, const string& s2)
{
setsequence;
for_each(s1.begin(),s1.end(),[&](const char& c){
if((auto pos = s2.find(c)) != -1)
{
sequence.insert(pos);
}
}
);
return;
}
int func()
{
string s1 = "some string";
string s2 = "some other string";
compare(s1,s2);
return 0;
}
int main() {
auto exit = (int (*)()) &func;
std::cout
Подробнее здесь: https://stackoverflow.com/questions/796 ... efore-auto