各位大神,小弟有的一个C++的问题,是关于类函数的使用和该类的全局变量使用冲突的问题

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”:类没有构造函数。该如何解决啊~~大神们

把Student的类定义放到一个单独头文件,然后再用的地方包含。

using namespace

这个问题是这样的。你的操作不是太规范,自然会遇到一些奇怪的问题。标准的C++编程规范中,类的申明和实现是分开的,你应该用一个student.h来申明类,用一个student.cpp实现该类的具体方法;然后在你的主cpp文件中include “student.h”就OK了,试试看。

Student *head=new Student(G_name,0,0);你把这句话写在class{};的后面就没事了

注意到你代码开始的位置有这么两行代码

class Student;
Student *head = new Student(G_name,0,0); 

你在这里仅仅作了一个前向声明,这种情况下使用Student *定义一个指针变量是没有问题。
但是new Student(G_name,0,0)这句代码实际是在调用Student类的构造函数创造该类的一个实例。
C/C++语法都要求先声明再调用,你的Student类是在你调用new Student之后才定义的(其实class Student{}这个操作用‘声明’来描述更准确一些)。
所以编译器认为Student * head没错,用new Student有错。

楼上的有道理或者你试试在public: 下面再加一条 Student(){} 看看行不行。

Student.h 和 Student.cpp 两个文件,

或者你可以都写在main.c 当中。。。

写类你可以分开,也可以在同一个文件中写。。