Can someone kindly explain why in the code below there is one line that generates an error ? For comparison, the next line compiles correctly. For some reasons, the casting to std::string is not the same as suppling a std:: string type variable. I am using Visual Studio 2019, C++, console application with default options.
#include <iostream>
#include <regex>
int main()
{
std::regex e;
std::smatch sm;
std::string str("abc");
std::regex_search(std::string("abc"), sm, e); // Doesn't compile
std::regex_search(str, sm, e); // Compiles correctly
}
Here's the error given by the pre-compiler Sorry for the italian...
Gravità Codice Descrizione Progetto File Riga Stato eliminazione Errore (attivo) E1776 impossibile fare riferimento a funzione "std::regex_search(const std::basic_string<_Elem, _StTraits, _StAlloc> &&, std::match_results::const_iterator, _Alloc> &, const std::basic_regex<_Elem, _RxTraits> &, std::regex_constants::match_flag_type = std::regex_constants::match_default) [con _StTraits=std::char_traits, _StAlloc=std::allocator, _Alloc=std::allocator, std::_String_iter_types>>>>>, _Elem=char, _RxTraits=std::regex_traits]" (dichiarato alla riga 2300 di "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\regex"). È una funzione eliminata ConsoleApplication3 C:\Users\munarid\source\repos\Unit-Test-Generation_Support\ConsoleApplication3\ConsoleApplication3.cpp 9