我有以下课程:
class Base {
protected:
int myint;
};
class Derived : public Base {
public:
bool operator==(Base &obj) {
if(myint == obj.myint)
return true;
else
return false;
}
};
Run Code Online (Sandbox Code Playgroud)
但是当我编译它时,它会出现以下错误:
int Base::myint在这种情况下受到保护
我认为受保护的变量可以在公共继承下从派生类访问.导致此错误的原因是什么?
我试图在C中实现一个纯粹作为练习的链表.我有这样的结构:
typedef struct node {
int data;
struct node* next;
}
node;
typedef struct list {
size_t size;
node* head;
}
list;
Run Code Online (Sandbox Code Playgroud)
现在,valgrind抱怨的功能是这些:
创建()
list* create() {
// alocate memory for a new list
list* list = malloc(sizeof(list));
if (list != NULL) {
list->head = NULL; // this is line 65
list->size = 0;
}
// return pointer to the allocated memory
return list;
}
Run Code Online (Sandbox Code Playgroud)
插入()
void insert(int data, list* list) {
if (list == NULL)
return;
// allocate memory …Run Code Online (Sandbox Code Playgroud)