In my project there are many lines with different values in the same area, for example:
std::string function_name = "name"; std::string hash = "0x123456"; std::string flag = "--configure";
I want to distinguish different lines by their value, use with function overloads:
void Process(const std::string& string_type1); void Process(const std::string& string_type2);
Obviously, I have to use different types:
void Process(const StringType1& string); void Process(const StringType2& string);
But how to implement these types in an elegant manner? All I can do is the following:
class StringType1 { std::string str_; public: explicit StringType1(const std::string& str) : str_(str) {} std::string& toString() { return str_; } };
Can you recommend a more convenient way?
It makes no sense to rename functions, since the main goal is not to erroneously pass one type of string instead of another:
void ProcessType1(const std::string str); void ProcessType2(const std::string str); std::string str1, str2, str3;
source share