我不确定这个为什么有效:
main.cpp:
int main(int argc, char * argv[]) {
Pwm_Info tf_info;
tf_info = get_pwm_info(library_data, motif_name);
}
Gen.cpp
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;
}
之前,我删除了指向TF_info和双向链表的指针,只保留了以下代码:
TF_info.pwm = double_list;
在这段代码中,指针(pointer和pointer2)相互赋值,导致了SegFault错误。 创建和相互赋值这些指针的目的是什么?
std::cout << TF_info.pwm[1] << std::endl;
在TF_info.pwm = double_list;
之前,并且指针部分还不存在,那么它当然不会起作用(TF_info.pwm
的原始长度为0
)。 - user3072164