C++ 将向量指定给结构';s向量场
我不知道为什么会这样: main.cpp:C++ 将向量指定给结构';s向量场,c++,pointers,vector,struct,segmentation-fault,C++,Pointers,Vector,Struct,Segmentation Fault,我不知道为什么会这样: main.cpp: int main(int argc, char * argv[]) { Pwm_Info tf_info; tf_info = get_pwm_info(library_data, motif_name); } 将军 struct Pwm_Info { std::string motif_name; int width; std::vector < double > pwm;
int main(int argc, char * argv[]) {
Pwm_Info tf_info;
tf_info = get_pwm_info(library_data, motif_name);
}
将军
struct Pwm_Info {
std::string motif_name;
int width;
std::vector < double > pwm;
Pwm_Info(): motif_name(0),
width(0),
pwm(0) {}
}
TF_info;
Pwm_Info get_pwm_info(std::string library_data, std::string motif_name) {
std::vector < double > double_list;
strtk::parse(pwm_block, " \n\r", double_list);
std::cout << double_list.size() << std::endl;
Pwm_Info TF_info;
TF_info.motif_name = motif_name;
TF_info.width = n_width;
std::vector < double > * pointer;
std::vector < double > * pointer2;
pointer = & TF_info.pwm;
pointer2 = & double_list; * pointer = * pointer2;
std::cout << TF_info.pwm[1] << std::endl;
TF_info.pwm = double_list;
return TF_info;
}
。。。这导致了一个断层。
创建和分配指针(指针和指针2)的意义是什么
pointer = &TF_info.pwm;
pointer2 = &double_list;
*pointer = *pointer2;
及
它们完全相等
唯一可能导致SEG故障的线路是:
std::cout << TF_info.pwm[1] << std::endl;
std::您能否提供一个简单的示例,说明在没有所有库数据、motif\u名称、Pwm\u信息、TF\u信息等情况下的问题。你能理解阅读这样的代码是很困难的吗?!你以前保留过印刷线吗?你提议的修改实际上是完全合法的。如果std::cout@Nabla,你是完全正确的。
TF_info.pwm = double_list;
std::cout << TF_info.pwm[1] << std::endl;