C++代码如下,求各位大神支招,其实应该很简单,还是我忘了一些语法~~代码什么的都不重要,就开头那里的几句关于提前声明类和定义该类的全局变量冲突了~~
#include
#include
#include
#include
#include
#include
using namespace std;
bool flag = true;
char G_name[20] = "";
class Student;
Student *head = new Student(G_name,0,0);
class Student
{
public:
Student(char *name, int number, int age)
{
int i = 0;
for (i = 0;i < sizeof(name);i++)
{
this->m_name[i] = name[i];
}
this->m_number = number;
this->m_age = age;
}
~Student()
{
cout << "删除该学生信息完毕" << endl;
}
void AddHead(Student *std)
{
cout << "请输入你想要插入的学生的姓名" << endl;
cin >> std->m_name;
cout << "请输入你想要插入的学生的学号" << endl;
cin >> std->m_number;
cout << "请输入你想要插入的学生的年龄" << endl;
cin >> std->m_age;
std->p = head;
head->p = NULL;
head = std;
std = NULL;
}
void AddTail(Student *std)
{
cout << "请输入你想要插入的学生的姓名" << endl;
cin >> std->m_name;
cout << "请输入你要插入的学生的学号" << endl;
cin >> std->m_number;
cout << "请输入你要插入的学生的年龄" << endl;
cin >> std->m_age;
Student *ff = NULL;
ff = head;
while (ff->p != NULL)
{
ff = ff->p;
}
ff->p = std;
std->p = NULL;
}
void Print()
{
Student *ff = NULL;
ff = head;
cout << "学生年龄" << " " << "学生姓名" << " " << "学生学号" << endl;
while (ff->p != NULL)
{
cout << ff->m_age;
cout << " ";
cout << ff->m_name;
cout << " ";
cout << ff->m_number << endl;
}
cout << ff->m_age;
cout << " ";
cout << ff->m_name;
cout << " ";
cout << ff->m_number << endl;
}
void Delete()
{
Student *ff = NULL;
Student *fx = NULL;
ff = head;
int number = 0;
cout << "请输入你要删除的学生的学号" << endl;
cin >> number;
while (ff->m_number != number)
{
ff = ff->p;
}
fx = ff;
ff = ff->p;
free(fx);
fx = NULL;
}
void Modify()
{
Student *ff = NULL;
Student *fx = NULL;
ff = head;
int number = 0;
cout << "请输入你要修改的学生的学号" << endl;
cin >> number;
while (ff->m_number != number)
{
ff = ff->p;
}
cout << "请输入修改后的学生姓名" << endl;
cin >> ff->m_name;
cout << "请输入修改后的学生学号" << endl;
cin >> ff->m_number;
cout << "请输入修改后的学生年龄" << endl;
cin >> ff->m_age;
}
void Exit()
{
cout << "您好,您已经退出" << endl;
}
private:
char m_name[20];
int m_number;
int m_age;
Student *p = NULL;
};
void print()
{
cout << "请输入您想要执行的命令的选项" << endl;
cout << "1.我想前插入一个学生信息" << endl;
cout << "2.我想后插入一个学生的信息" << endl;
cout << "3.我想打印所有当前学生的信息" << endl;
cout << "4.我想删除某位学生的信息" << endl;
cout << "5.我想修改某位学生的信息" << endl;
cout << "6.我什么也不想做,直接退出" << endl;
}
void Execute()
{
int a = 0;
cin >> a;
char name[20] = "";
int number = 0;
int age = 0;
Student *stud = new Student(name, number, age);
switch (a)
{
case 1:
head->AddHead(stud);
break;
case 2:
head->AddTail(stud);
break;
case 3:
head->Print();
break;
case 4:
head->Delete();
break;
case 5:
head->Modify();
break;
case 6:
flag = false;
break;
default:
break;
}
}
int main(void)
{
while (flag)
{
print();
Execute();
}
system("pause");
return 0;
}
最后编译器就给我一句话:“Student”:类没有构造函数。该如何解决啊~~大神们