Код: Выделить всё
namespace mylib
{
template
struct String
{
String()
{
*data = '\0';
}
String(const char *str)
{
size_t l = strlen(str);
if (l >= N)
throw std::runtime_error(str);
memcpy(data, str, l + 1);
}
auto operator(const String& str) const
{
return data str.data;
}
char data[N];
};
}
void test_string()
{
mylib::String str1;
mylib::String str2("Hallo");
mylib::String str3 = "Hallo";
mylib::String str4 = "hallo";
assert(str2 == str3);
assert(str4 != str2);
assert(str2 < str4);
assert(str2 str2);
assert(str4 >= str2);
mylib::String str5 = "Hallo";
}
Код: Выделить всё
1>E:\Projects\Windows\ind\IndDlg.cpp(104,2): error C2678: binary '==': no operator found which takes a left-hand operand of type 'mylib::String' (or there is no acceptable conversion)
1> 'bool operator ==(const D2D1_SIZE_U &,const D2D1_SIZE_U &)': cannot convert argument 1 from 'mylib::String' to 'const D2D1_SIZE_U &'
Он должен иметь возможность сравнивать строки разного размера:
Код: Выделить всё
String < String
Я использую Visual Studio 2022 C++ 20.
Подробнее здесь: https://stackoverflow.com/questions/792 ... late-class