|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
语法没有错误,但是控制台显示分配不了内存,不知道是哪的逻辑错误?求大佬解决下
#include "stdafx.h"
#include "iostream"
using namespace std;
class person
{
private:
string name;
int age;
char sex;
public:
void getname();
void getage();
void getsex();
void putname();
void putage();
void putsex();
};
void person::getname()
{
cin >> this->name;
}
void person::getage()
{
cin >> this->age;
}
void person::getsex()
{
cin >> this->sex;
}
void person::putname()
{
cout << "姓名:" << name <<endl;
}
void person::putage()
{
cout<<"年龄:" << age << endl;
}
void person::putsex()
{
cout << "性别" << sex << endl;
}
struct node
{
person * A;
struct node * pnext;
};
struct node * creat_list(void)
{
//创建一个头指针
struct node * phead;
struct node * pnext;
struct node * pnew;
pnext = phead;
pnext->A = new person;
pnext->A->getname();
pnext->A->getage();
pnext->A->getsex();
pnext->pnext = NULL;
int num;
cin >> num;
for (int i=0;i<num;i++)
{
pnew->A = new person;
pnew->A->getname();
pnew->A->getage();
pnew->A->getsex();
pnew->pnext = NULL;
pnext->pnext = pnew;
pnext = pnew;
}
return phead;
}
int main ()
{
struct node * phead;
phead = creat_list();
return 0;
} |
|