大家好,我是新手。今天在C++教程上原封的敲了一段程序,在VC++上。程序如下:
#include<iostream.h>
class figure{
protected:
double x,y;
public:
firgure(double a,double b)
{x=a;y=b;}
virtual void show_area()
{cout<<"No area computation defined";
cout<<"for this class.\n";
}
};
class triangle: public figure
{public:
trigngle(double a,double b):figure(a,b)
{};
void show_area()
{cout<<"Triangle with height"<<x;
cout<<"and base"<<y<<"has an area of";
cout<<x*y*0.5<<endl;}
};
class square:public figure{
public:
square(double a,double b):figure(a,b)
{};
void show_area()
{cout<<"Square with dimension"<<x;
cout<<"*"<<y<<"has an area of";
cout<<x*y<<endl;
}
};
class circle:public figure{
public:
circle(double a):figure(a,a)
{};
void show_area()
{cout <<"Circle with radius"<<x;
cout<<"has an area of";
cout<<x*x*3.1416<<endl;
}
};
main()
{figure *p;
triangle t(10.0,6.0);
square s(10.0,6.0);
circle c(10.0);
p=&t;
p->show_area();
p=&s;
p->show_area();
p=&c;
p->show_area();
return 0;
}
这个程序的功能是求三角形,圆形和矩形的面积。可是我按F5后,出现了如下的提示
--------------------Configuration: my_test - Win32 Debug--------------------
Compiling...
my_test.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/my_test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
my_test.exe - 2 error(s), 0 warning(s)
由于我是新手。我想知道我的上面的程序有问题吗。还是出现了什么语法错误。我用的教程是清华出版社出版的C++教程。运行环境是VC++,希望哪位能帮我。感激不胜!