友元类
程序如下,为何编译出错,显示Segmentation Fault (core dumped),请指教
#include <iostream>
using namespace std;
const int len = 10;
class Node
{
public:
friend class Chain;
private:
int date;
char ch[len];
Node* next;
};
class Chain
{
public:
Chain();
~Chain();
void Output(ostream& out)const;
private:
int length;
Node* first;
};
Chain::Chain()
{
length = 0;
first = NULL;
}
Chain::~Chain()
{
Node* link;
while (first)
{
link = first->next;
delete first;
first = link;
}
link = NULL;
}
void Chain::Output(ostream& out)const
{
out << first->date;
}
int main()
{
Chain CS;
CS.Output(cout);
}