k12305
k12305
采纳率33.3%
2016-06-13 11:37

c++ 模板类问题 运行不了 ,总说没定义 求大神解答

#ifndef JJ
#define JJ
#include "Teacher.h"
#include "User.h"
#include
#include
#include
using namespace std;
template
class Personal:public Teacher
{
private:
time_t t; //存储发帖时间
char subject[30]; //帖子主题
char contents[200]; //帖子内容
char Time[50];
public:
Personal(){}
void CopyInformation(T &A);
void SaveIntoPersonal();
void SetTime();
void CreatPersonal(T &A);
void DisplayPersonal(); //删除帖子,打印帖子
void DeletePersonal();

};
int PersonalMenu();
template
int PrintList();
template
int PrintPersonalList(T &);
template
int DeletePersonals(T &);
template
int main_Personal(T &);
#endif

#include "Personal.h"
#include
using namespace std;
int PersonalMenu()
{
int choice;
cout<<"************************************************\n";
cout<<"* ~欢迎进入个人模块~ \n";
cout<<"
***********************************************\n";
cout<<"* 1、查看公告栏信息 \n";
cout<<"
2、查看个人帖子 \n";
cout<<"
3、查看个人信息 \n";
cout<<"
4、修改个人信息 \n";
cout<<"
5、发布个人帖子 \n";
cout<<"
6、删除个人帖子 \n";
cout<<"
0、返回上级 \n";
cout<<"
***********************************************\n\n";
cout<<"请输入要操作的序号:";
cin>>choice;
return choice;
}
template
void Personal::SetTime()
{
t=time(NULL);
strftime(Time,sizeof(Time),"%Y-%m-%d",localtime(t));
}
template
void Personal::CreatPersonal(T &A)
{
CopyInformation(A);
system("cls");
cout<<"\t\t\t创建新的帖子\n";
cout<<"请输入主题(不超过20个字):\n";
cin>>subject;
cout<<"输入内容:\n";
getchar();
gets(contents);
SetTime();
SaveIntoPersonal();
cout<<"发布成功\n";
system("pause");
system("cls");
}
template
void Personal::SaveIntoPersonal()
{
ofstream outf("Personal.txt",ios::app);
if (!outf)
{
cout<<"fail to open Personal.txt\n";
exit(0);
}
outf.write((char )this,sizeof(Personal));
outf.close();
}
template
void Personal::DeletePersonal()
{
fstream fps("Personal.txt",ios::in|ios::out);
if (!fps)
{
cout<<"fail to open Personal.txt\n";
exit(0);
}
int flag=0,num=0;
while(flag==0&&!fps.eof())
{
Personal A;
fps.read((char *)&A,sizeof(Personal));
if (t==A.t)
{
flag=1;
}
num++;
}
strcpy(username,"NULL");
strcpy(subject,"NULL");
strcpy(contents,"NULL");
fps.seekg(sizeof(Personal)
(num-1),ios::beg);
fps.write((char *)this,sizeof(Personal));
fps.close();
cout<<"删除成功!\n";
system("pause");
system("cls");
}
template
void Personal::DisplayPersonal()
{
cout<<"\t\t主题:"< cout cout }
template
void Personal::CopyInformation(T &A)
{
int b=A.GetIsAdmin();
strcpy(username,A.GetUsername());
strcpy(password,A.GetPassword());
strcpy(name,A.GetName());
strcpy(ID,A.GetID());
IsForbid=A.GetIsforbid();
if (b==1)
{

}
if (b==2)
{
}
if (b==3)
{
    strcpy(Profession,A.GetProfe());
    strcpy(Academic,A.GetAcade());
    strcpy(Academic,A.GetIntro());
}

}
template
int PrintList()
{
ifstream inf("Personal.txt");
if (!inf)
{
cout<<"Fail to open Personal.txt\n";
exit(0);
}
int num;
while(!inf.eof())
{
Personal C;
inf.read((char *)&C,sizeof(Personal));
num++;
cout< C.DisplayPersonal();
}
inf.close();
return 0;
}
template
int PrintPersonalList(T &A)
{
ifstream inf("Personal.txt");
if (!inf)
{
cout<<"Fail to open Personal.txt\n";
exit(0);
}
int num;
while(!inf.eof())
{
Personal C;
inf.read((char *)&C,sizeof(Personal));
if (strcmp(A.GetUsername(),C.GetUsername())==0)
{
num++;
cout< C.DisplayPersonal();
}
}
inf.close();
return 0;
}
template
int DeletePersonals(T &A)
{
PrintPersonalList(A);
Personal B;
int flag=0;
while(flag==0)
{
int a;
cout<<"输入要删除的序号\n";
cin>>a;
fstream fps("Personal.txt",ios::in|ios::out)
if(!fps)
{
cout<<"Fail to open Personal.txt\n";
exit(0);
}
int num=0;
fps.read((char *)&B,sizeof(Personal));
if (strcmp(A.GetUsername(),B.GetUsername())==0)
{
num++;
if (num==a)
{
flag=1;
}
}
fps.close();
}
B.DeletePersonal();
}
template
int main_Personal(T &A)
{
Personal B;
int a;
do
{
a=PersonalMenu();
switch(a)
{
case 1:PrintList();
break;
case 2:PrintPersonalList(B);
break;
case 3:A.Display();
break;
case 4:A.Alter();
break;
case 5:B.CreatPersonal(A);
break;
case 6:DeletePersonals(A);
break;
default:cout<<"输入有误\n";
}
system("pause");
system("cls");
} while (a!=0);
return 0;
}

#include "User.h"
#include "Teacher.h"
#include "Personal.h"
#include
using namespace std;
int main()
{
Teacher b;
b.CreatTea();
Personal B;
B.CreatPersonal(b);
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

相关推荐