注册 登录
编程论坛 C++教室

提示链接错误,怎么回事?

maiiho 发布于 2008-10-11 17:37, 575 次点击
这是程序
#include <iostream.h>
#include <string.h>
class student
{
private:
    char *no;
    char *name;
    float grade;
    static int count;
    static float sum;
public:
    student(char *name1,char *no1,float grade1);
    ~student();
    void show();
    static void show_count_sum();
};
student::student(char *name1,char *no1,float grade1)
{
    name=new char[strlen(name1)+1];
    strcpy(name,name1);
    no=new char[strlen(no1)+1];
    strcpy(no,no1);
    grade=grade1;
    --count;
    sum=sum+grade;
}
student::~student()
{
    delete []name;
    delete []no;
    --count;
    sum=sum-grade;
}
void student::show()
{
    cout<<"\n人数:"<<count;
    cout<<"\n学号:"<<no;
    cout<<"\n成绩:"<<grade;
}
void student::show_count_sum()
{
    cout<<"\n 人数:"<<count;
    cout<<"\n 成绩:"<<sum;
}
int student::count=0;
float student::sum=0;
void mian()
{
    student stu1("maiiho","95001",95);
    stu1.show();
    student::show_count_sum();
    student stu2("shimizu","95002",85);
    stu2.show();
    stu2.show_count_sum();
}
    


这是出错信息
--------------------Configuration: ore - Win32 Debug--------------------
Compiling...
ore.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/ore.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

ore.exe - 1 error(s), 0 warning(s)
2 回复
#2
maiiho2008-10-11 17:41
另外还有,虚构函数里面为什么和构造函数的所有操作都相反?
有什么作用?
难道在执行student stu1("maiiho","95001",95);的时候,调用构造函数
那么程序结束,然后调用虚构函数,把构造函数的数据都消除掉,是不是这个意思?
#3
kevin882008-10-11 18:18
回复 2# maiiho 的帖子
虚构函数和构造函数的作用差不多就是这样的了,具体你再找资料看下,其余楼下补充。。。。
1