class S
{
string season;
staticconst string seasons[];
public:
S()
{
}
void seek(string& s)
{
/// compilation-error
const string* p = find(begin(seasons), end(seasons), s);
if (p == end(seasons))
cout << s << " not found" << endl;
else
cout << s << " found" << endl;
}
};
const string S::seasons[]
{
"spring", "summer", "fall", "winter"
};
Compilation-error is:
In member function 'void S::seek(std::string&)':|
error: no matching function for call to 'begin(const string [])'|
Note: candidates are:
note: template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)|
etc....
What is the solution?
The error doesn't occur outside a class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const string seasons[]
{
"spring", "summer", "fall", "winter"
};
void test(const string& s)
{
/// OK
const string* p = find(begin(seasons), end(seasons), s);
if (p == end(seasons))
cout << s << " not found" << endl;
else
cout << s << " found" << endl;
}