Код: Выделить всё
#include
#include
#include
struct Foo
{
std::string bar = "standard";
int x = 1;
int y = 1;
bool operator==(const Foo&) const = default;
bool operator!=(const Foo&) const = default;
void ResetToStandard()
{
bar = "standard";
x = 1;
y = 1;
}
};
int main(int argc, char* argv[])
{
Foo f, g;
g.bar = "Hello world!";
g.x = 123;
g.y = 234;
g.ResetToStandard();
assert(f == g);
}
Тогда я придумал это, что работает нормально.
void ResetToStandard()
{
*this = Foo();
}
< /code>
Это общий шаблон? Это идиоматический способ?
Подробнее здесь: https://stackoverflow.com/questions/796 ... ult-values
Мобильная версия