class Student { public: int id; std::string name; };
int main(int argc, char const* argv[]) { int size = 10; Student* st = (Student*)malloc(sizeof(Student) * size); for (Student* i = st; i < st + size; i++) { i->id = 123; i->name = "qiumc"; } // 如果要释放st内存,仅仅需要free(st);既可以,不能把st当做一个数组,进行逐个释放。 return 0; }