chatgpt重构的,其实是差不多的。提示词说要短,它居然把成员的可读性干掉了。
struct Person(String, u32);
impl Person {
fn greet(&self) {
println!("Hello, I'm {} and I'm {} years old.", self.0, self.1);
}
}
fn main() {
for p in [Person("Alice".into(), 25), Person("Bob".into(), 30), Person("Charlie".into(), 35)] {
p.greet();
}
}
#include <iostream>
struct Person {
std::string n; int a;
void g() const { std::cout << "Hello, I'm " << n << " and I'm " << a << " years old.\n"; }
};
int main() {
for (auto [n,a] : {std::pair{"Alice",25}, {"Bob",30}, {"Charlie",35}})
Person{n,a}.g();
}
--
修改:z16166 FROM 221.220.174.*
FROM 221.220.174.*