我有一个带有多个const声明的结构。我知道,当您的结构体中有一个const时,您可以在构造函数中隐式声明其值。但是,当我尝试对多个const执行此操作时,它将无法编译。在构造函数中声明多个const的正确方法是什么?
struct RLdata { const double alpha; const double gamma; const double beta; int count = 0; bool action; //0 = BUY, 1 = SELL double Qbuy = 1; double Qsell = 0; std::vector reward; //This below works if I just have one of the variables implicitly, but not with 3. RLdata(const double &a, const double &g, const double &b) : alpha(a), gamma(g), beta(b){} };
./RL.h:29:8: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 3 were provided struct RLdata ^ ./RL.h:29:8: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 3 were provided 1 error generated.