class NU
{
private:
std::string nucname;
double activity_1;
double activity_2;
double activity_3;
public:
void factor1(const std::string & co, double act_class_1, double act_class_2, double act_class_3);
void show();
};
类声明如上
const int s = 4;
NU nuc_class[s] = { NU("Ba137",0,0,0),NUCLEAR("ZN 69M",0,0,0),NU("ZN 69M",0,0,0),NU("ZN 69M",0,0,0) };//生成10个类,此处生成4个
初学c++,简单创建了对象数组,结果vs编译显示无法从“initializer list”转换为“NU”
无构造函数可以接受源类型,或构造函数重载决策不明确
很疑惑,调试不出来,各路大神不吝赐教哇,谢谢!
在类中加入构造函数,对的类的成员变量进行初始化 NU(string nucname, double activity_1,double activity_2,double activity_3){
this->nucname = nucname;
this->activity_1 = activity_1;
this->activity_2 = activity_2;
this->activity_3 = activity_3;
}
在头文件中添加NUCLEAR();
后在.cpp文件中添加构造函数,问题得以解决
NU::NU()
{
nucname = "no name";
activity_1 = 0.0;
activity_2 = 0.0;
activity_3 = 0.0;
activity_4 = 0.0;
activity_5 = 0.0;
activity_6 = 0.0;
activity_7 = 0.0;
activity_8 = 0.0;
activity_9 = 0.0;
activity_10 = 0.0;
}
本人是新手,这一构造函数好理解些。大神的构造函数有空我再看看