gpt4 book ai didi

c++ - 警告 : non-static data member initializers only available with -std=c++11 or -std=gnu++11?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:16:15 25 4
gpt4 key购买 nike

<分区>

我有这个代码

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 的私有(private)部分下声明对象 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

虽然它给了我警告但显然它没有影响程序运行。它实际上有什么影响吗?我在这里做错了什么?

编辑:静态成员初始值设定项和非静态成员初始值设定项之间的区别是什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com