Compiler Warning C26486 ranged for-loop

  • Thread starter Thread starter Dr. DavidBear
  • Start date Start date
D

Dr. DavidBear

Guest
So, I'm just not getting the whole lifetime thing with this code:


using D_String = Multi_String<String_Type::dictionary>;

int main()


{
std::vector<D_String> dictionary_vector = { "cat","CAT","DOG","dog",
"fish","Dog","" };

std::cout << "Before sort : ";
for (const auto& s : dictionary_vector) std::cout << s << " "; // Highlights cout << s


For What its worth, The constructor for Multi_String looks like this:

template <String_Type ST>
class Multi_String
{
std::string s;
public:
Multi_String(const char* cstr) : s{ cstr } {}
Multi_String(const std::string& s_) : s{ s_ } {}
Multi_String(std::string&& s_) noexcept : s{ std::move(s_) } {}
auto operator<=>(const Multi_String<ST>& rhs) const;
bool operator==(const Multi_String<ST>& rhs) noexcept;
const char* c_str() const noexcept;

friend std::ostream& operator<< (std::ostream& out, const Multi_String<ST>& s);
};



Any clue as to how this warning is helping the user (me)? Are there things that I should be actually doing about this code to make the error go away (other than #pragma warning(disable:26486)?

Thanks!

Continue reading...
 
Back
Top