当我尝试在dequeue()函数中为Student的name字段释放char数组时,程序崩溃了.内存先前已在createStudent()函数中分配.
我真的看不出我想念的东西.
#include "iostream"
#include "stdio.h"
using namespace std;
struct Student
{
int id;
char* name;
};
struct QueueNode
{
Student* info;
QueueNode* next;
};
Student* createStudent(int id, char* name)
{
Student* s = (Student*)malloc(sizeof(Student));
s->id = id;
s->name = (char*)malloc(sizeof(name) + 1);
strcpy(s->name, name);
return s;
}
QueueNode* createQueueNode(Student *s)
{
QueueNode *queue = (QueueNode*)malloc(sizeof(QueueNode));
queue->info = s;
queue->next = nullptr;
return queue;
}
void enqueueNode(QueueNode* &root, QueueNode* node)
{
if (root == nullptr)
root = node;
else
{ …Run Code Online (Sandbox Code Playgroud) 如果接口不应该在C#中具有属性,那么如何在接口中拥有属性,因为属性是属性的getter和setter?在类中我们有这个例子,我认为接口应该只有方法声明.
interface IKnownProgrammingLanguages
{
string[] ProgrammingLanguages { get; set; }
}
Run Code Online (Sandbox Code Playgroud)