主题:怎么把类中的成员函数拿到类外面来定义
请问下:怎么把类ActList中的Create函数拿到类外面来定义,我试了下老报错
#include "stdafx.h"
#include <iostream>
using namespace std;
class ActList;
class ListNode
{
friend class ActList;
public:
char ActName[20];
char director[20];
int Mtime;
ListNode *next;
ListNode(){};
~ListNode(){};
};
class ActList
{
public:
ListNode *head;
void displayList(ListNode *pHead);
ActList(){};
~ActList(){};
ListNode *Create()
{
ListNode *p = NULL; //待插入的节点
ListNode *q = NULL; //当前节点,用于在其后插入节点
head = NULL;
int Time;
cout<<"输入节目时长:";
cin>>Time;
while (Time != 0)
{
p = new ListNode;
p->Mtime = Time;
cout<<"输入节目名称:";
cin>>p->ActName;
cout<<"输入主持人:";
cin>>p->director;
if (head == NULL)
{
head = p;
}
else
{
q->next = p;
}
q = p;
cout<<"\n输入节目时长:";
cin>>Time;
}
if (head != NULL)
{
q->next = NULL;
}
return(head);
}
};
void ActList::displayList(ListNode *pHead)
{
cout<<"\n显示节目列表\n";
while(pHead != NULL)
{
cout<<pHead->Mtime<<endl
<<pHead->ActName<<endl
<<pHead->director<<endl
<<endl;
pHead = pHead->next;
}
}
int main()
{
ActList list;
list.displayList(list.Create());
return 0;
}