give_me_a_name是什么意思?

what does the give_me_a_name mean?

本文关键字:意思 是什么 me give name      更新时间:2023-10-16

我是 c++ 的新手,我在 clion 中编写了以下代码:

Student student[] = {
Student("Larry", 95.5, "This is Larry", 1);
Student("Paul", 78.0, "This is Paul", 2);
Student("Tom", 80.0, "This is Tom", 3);
};

它暗示了一个叮叮当当的整洁:object destroyed immediately after the creation; did you mean to name the object?如果我遵循它,代码将更改为:

Student student[] = {
Student("Larry", 95.5, "This is Larry", 1);
Student give_me_a_name("Paul", 78.0, "This is Paul", 2);
Student("Tom", 80.0, "This is Tom", 3);
};

那么give_me_a_name是什么意思呢?为什么会有这样的语法?

这正是它听起来的样子。你使用了分号而不是逗号,这让 Clang 认为你正在构造一个对象,并立即丢弃它,就好像你自己Student("Paul", 78.0, "This is Paul", 2);一样。因此,它建议您通过为其命名来将构造的对象存储在变量中。Clang 不知道你想要什么名字,所以它会在那里放置一个占位符名称供您替换。