计算机大二生,初学c++,老师让做个图书馆的程序,要求用链表和继承,然后还要用文件。手动满脸绝望。花了三四天才写成这样,但是出现了个这样的错误 。
LNK2001 无法解析的外部符号 "class person * * p_per" (?p_per@@3PAPAVperson@@A) 图书馆 D:\C++\实验\图书馆\图书馆\源.obj 1
不知要怎么改,看网上的解释是因为编译环境,但我觉得错误里有这个class person ** ,应该不是环境的问题,想让各位大佬看看可是我什么地方没写对,概念模糊了。
以下代码是,一个基类item,底下种种派生,一个librery类以供操作,person储存用户信息,储存方式都是链表,在item后面建了两个指针,两个数组。
class person
{
public:
person(string n = "jk", string add = "207", int m = 666666)
{
name = n; address = add; mima = m;
}
virtual ~person() { delete this; }
person*next;
string name, address; int mima;
private:
};
class item
{
public:
item(string n=" ",int number=00000,string d=" ")
{
name = n; num = number; data = d;
}
virtual ~item() { delete this; }
item*search(int);//链表头结点地址和作品编号
void display(int);//链表头结点地址和类型,类型编号不写默认为全输出
void borrow(int ,string);//作品编号和借阅人姓名
item*next;
protected:
string name, data;//名称与发行日期
int num;//项目编号
string writer; //作者
float room;//储存空间
float time;//周期
string actor;//演员
float level;//清晰等级
int zhuagntai = 1;//zhuangtai是用来查看是否被借用的,1为未被借用,0为被借用
int chose = 0;
string person ;//借阅人姓名
private:
};
item* it = NULL;
item* p[];
person*per = NULL;
person *p_per[];
void item::borrow(int ch ,string pername)
{
int n;
loop:
item*q = search(ch);
q->person = pername;
q->zhuagntai = 0;
cout << "请问是否还需要借书,需要请输入1"<<endl;
cin >> n;
if(n==1)
{
cout << "请输入作品编号" << endl;
cin >> ch;
goto loop;
}
cout << "尊敬的" << pername << ",您已借阅成功,请按时归还";
}
void item::display(int ch=0)
{
item *p = it->next;
cout << "所有项目如下:" << endl;
if (p == NULL)
{
cout << "======================================" << endl;
cout << " 并没有任何项目!! " << endl;
cout << "======================================" << endl;
return;
}
for (; p != NULL; p = p->next)
{
if (ch == p->chose||ch==0)
{
cout << "======================================" << endl;
cout << "作品名称为:" << p->name << endl;
cout << "发行日期为:" << p->data << endl;
cout << "作品编号为:" << p->num << endl;
if (p->chose == 1)
cout << "作者为:" << p->writer << endl;
if (p->chose == 2)
cout << "发行间隔为:" << p->time << endl;
if (p->chose == 3)
cout << "作品储存空间为:" << p->room << endl;
if (p->chose == 4)
{
cout << "作品演员有:" << p->actor << endl;
cout << "作品储存空间为:" << p->room << endl;
}
if (p->chose == 5)
{
cout << "作品演员有:" << p->actor << endl;
cout << "作品清晰等级为:" << p->level << endl;
}
cout << "======================================" << endl;
}
}
}
item* item::search(int n)
{
bool have = 0; item*p = it, *found = NULL;
for (p; p != NULL; p->next)
{
if (p->num == n)
{
have = 1;
found = p;
}
}
if (have == 0)
{
cout << "======================================" << endl;
cout << "查无此项目!!" << endl;
cout << "======================================" << endl;
}
return found;
}
class book :public item
{
public:
book(string n = " ", int number = 00000, string d = " ",string w=" ")
{
name = n; num = number; data = d; writer = w;
}
private:
const int chose = 1; string writer;
};
class music :public item
{
public:
music(string n = " ", int number = 00000, string d = " ",float r=0)
{
name = n; num = number; data = d; room = r;
}
private:
const int chose = 3; float room;
};
class magizne :public item
{
public:
magizne(string n = " ", int number = 00000, string d = " ",string t=" ")
{
name = n; num = number; data = d; time = t;
}
private:
const int chose = 2; string time;
};
class movie :public item
{
public:
movie(string n = " ", int number = 00000, string d = " ", string act=" ")
{
name = n; num = number; data = d; actor = act;
}
string actor;
private:
const int chose = 0;
};
class dvd :public movie
{
public:
dvd(string n = " ", int number = 00000, string d = " ", string act = " ",float r=0)
{
name = n; num = number; data = d; actor = act; room = r;
}
private:
const int chose = 4; float room;
};
class languang :public movie
{
public:
languang(string n = " ", int number = 00000, string d = " ", string act = " ",int lev=1)
{
name = n; num = number; data = d; actor = act; level = lev;
}
private:
const int chose = 5; int level;
};
class library
{
public:
library();
void welcome();
person* denglu();
void gongneng();
private:
};
library::library()
{}
void library::welcome()
{
denglu();
gongneng();
}
person* library::denglu()
{
string name_1; int mima_1; person*p = per; int x = 0;
loop:
cout << "请输入您的用户名和密码" << endl;
cin >> name_1;
cin >> mima_1;
for (p; p != NULL; p = p->next)
{
if (p->name == name_1&&p->mima == mima_1)
;
else
{
cout << "用户名或密码错误,请重新输入" << endl;
cout << "如果需要退出,请回复1";
loop1:
cin >> x;
if (x == 0)
goto loop;
if (x == 1)
return NULL;
else
{
cout << "错误指示,请重新输入";
goto loop1;
}
}
}
return p;
}
void library::gongneng()
{
int y = 0;
while (1)
{
cout << "请选择您所需要的服务"<<endl
<< "1.查询所有项目" << endl
<< "2.借阅" << endl
<< "请输入:" << endl;
cin >> y;
if (y == 1)
{
int leixin = 0;
cout << "请输入你要查询的项目类型" << endl
<< "1为书籍类,2为杂志类,3为音乐类,4为电影DVD类,5为电影蓝光类" << endl;
cin >> leixin;
it->display(leixin);
}
if (y == 2)
{
int n;
cout << "请输入您要借阅的项目编号" << endl;
cin >> n;
person*p = denglu();
if (p == NULL) { continue; }
it->borrow(n, p->name);
}
}
}
void Add(item*h, item*t)
{
t->next=h; h = t;
}
void add(person*h,person*t)
{
t->next = h; h = t;
}
int main()
{
library lib;
p[1] = new item();
p[2] = new book("c++真得难", 1, "2018/12/10", "jk");
p[3] = new music("程序员之歌", 2, "2018/12/8", 2.0);
p[4] = new magizne("程序员的自我修养", 3, "2018/12/9", "7day");
p[5] = new dvd("python从入门到放弃", 4, "2018/12/11","jk", 600.5);
p[6] = new languang("学习c++吧,少年", 5, "2018/12/7","j_k", 5);
for (int i = 1;i<=6; i++)
{
Add(it,p[i]);
}
p_per[1] = new person();
p_per[2] = new person("j_K", "208-1", 666666);
add(per, p_per[1]);
add(per, p_per[2]);
lib.welcome();
}