【发布时间】:2026-02-10 12:50:01
【问题描述】:
我有这个代码
class Move
{
public:
Move()
{
name = "";
type_num = 18;
power = 0;
accuracy = 0;
type = "???";
}
Move(string a, int b, int c, int d)
{
name = a;
type_num = b;
power = c;
accuracy = d;
/*lines of code to give type a string variable depending on the value of type_num*/
}
private:
string name, type;
int type_num, power, accuracy;
};
class Moveset
{
public:
Moveset()
{
}
private:
Move slot1{"MOVE 1", rand() % 18, 10*(rand() % 15 + 1), 5 * (rand() % 11 + 10)};
};
编译器给了我这个警告,用于在 Moveset 类的私有部分下声明对象 slot1。
464 83 C:\Users\N\Desktop\C++\Poke\Poke.cpp [Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11
464 15 C:\Users\N\Desktop\C++\Poke\Poke.cpp [Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11
464 83 C:\Users\N\Desktop\C++\Poke\Poke.cpp [Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11
虽然它给了我警告,但显然它并没有影响程序运行。它实际上会影响什么吗?我在这里做错了什么?
编辑:静态成员初始化器和非静态成员初始化器有什么区别?
【问题讨论】:
-
我投票决定将这个问题作为新问题的副本来结束,而不是相反,因为另一个问题准确地显示了哪些代码行给出了我认为更清楚的警告。跨度>
-
同意......