关于类内的结构体的构造函数
上一个贴结早了......
#include<iostream>using namespace std;class Linked{ protected: struct Node{ int item; Node *next; Node():next(NULL),item(0){} //此处添加了构造函数 }; Node* head; long length; public: Linked(){ length=0; } void insert(int i){ if((head->next)==NULL){ Node* newItem; newItem->item=i; head->next=newItem; length++; cout<<this->length; } } };int main(){ Linked itr; itr.insert(2); system("pause"); return 0;}
Unhandled exception at 0x004114c8 in test.exe: 0xC0000005: Access violation reading location 0xccccccd0.First-chance exception at 0x004114c8 in test.exe: 0xC0000005: Access violation reading location 0xccccccd0.