struct LeafDataEntry
{
void *key;
int a;
};
int main(){
//I want to declare a vector of structure
vector<LeafDataEntry> leaves;
for(int i=0; i<100; i++){
leaves[i].key = (void *)malloc(sizeof(unsigned));
//assign some value to leaves[i].key using memcpy
}
}
在上面的 for 循环中执行 malloc 时,我收到此代码的 SEG FAULT 错误....有关将内存分配给结构向量中的指针的任何替代方法的任何建议。