我用VC++6.0调试这个小程序,可是出错!我不知如何改,请帮帮忙!
出错显示为:
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
C:\TEMP\1\1.cpp(23) : error C2236: unexpected 'class' 'circle'
C:\TEMP\1\1.cpp(23) : error C2143: syntax error : missing ';' before ':'
C:\TEMP\1\1.cpp(23) : error C2143: syntax error : missing ';' before ':'
C:\TEMP\1\1.cpp(23) : error C2143: syntax error : missing ';' before 'public'
C:\TEMP\1\1.cpp(24) : error C2143: syntax error : missing ';' before '{'
C:\TEMP\1\1.cpp(24) : error C2447: missing function header (old-style formal list?)
C:\TEMP\1\1.cpp(32) : error C2079: 'oneshape' uses undefined class 'circle'
C:\TEMP\1\1.cpp(36) : error C2228: left of '.fun' must have class/struct/union type
C:\TEMP\1\1.cpp(37) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.1.exe - 8 error(s), 1 warning(s)
//以下是程序// 1.cpp : Defines the entry point for the application.
//#include "stdafx.h"
#include <iostream.h>
/*int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
//{
*/
class shape
{
public:
void draw()
{cout<<"我是一位VC++初学者"<<endl;
cout<<"这里显示的是基类"<<endl;
}
void fun()
{draw();};
}
class circle : public shape
{
public:
void draw()
{cout<<"这是一个子类"<<endl;}
} main()
{
class circle oneshape;
cout<<"这个例子是在学习C++的多态性"<<endl;
cout<<"动态联编:虚函数"<<endl;
cout<<"我希望显示的是子类"<<endl;
oneshape.fun();
}
出错显示为:
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
C:\TEMP\1\1.cpp(23) : error C2236: unexpected 'class' 'circle'
C:\TEMP\1\1.cpp(23) : error C2143: syntax error : missing ';' before ':'
C:\TEMP\1\1.cpp(23) : error C2143: syntax error : missing ';' before ':'
C:\TEMP\1\1.cpp(23) : error C2143: syntax error : missing ';' before 'public'
C:\TEMP\1\1.cpp(24) : error C2143: syntax error : missing ';' before '{'
C:\TEMP\1\1.cpp(24) : error C2447: missing function header (old-style formal list?)
C:\TEMP\1\1.cpp(32) : error C2079: 'oneshape' uses undefined class 'circle'
C:\TEMP\1\1.cpp(36) : error C2228: left of '.fun' must have class/struct/union type
C:\TEMP\1\1.cpp(37) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.1.exe - 8 error(s), 1 warning(s)
//以下是程序// 1.cpp : Defines the entry point for the application.
//#include "stdafx.h"
#include <iostream.h>
/*int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
//{
*/
class shape
{
public:
void draw()
{cout<<"我是一位VC++初学者"<<endl;
cout<<"这里显示的是基类"<<endl;
}
void fun()
{draw();};
}
class circle : public shape
{
public:
void draw()
{cout<<"这是一个子类"<<endl;}
} main()
{
class circle oneshape;
cout<<"这个例子是在学习C++的多态性"<<endl;
cout<<"动态联编:虚函数"<<endl;
cout<<"我希望显示的是子类"<<endl;
oneshape.fun();
}
{
...
}; <--分号
//#include "stdafx.h"
#include <iostream.h>
/*int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
//{
*/
class shape
{
public:
void draw()
{cout<<"我是一位VC++初学者"<<endl;
cout<<"这里显示的是基类"<<endl;
}
void fun()
{draw();};
};
class circle : public shape
{
public:
void draw()
{cout<<"这是一个子类"<<endl;}
}; main()
{
circle oneshape;
cout<<"这个例子是在学习C++的多态性"<<endl;
cout<<"动态联编:虚函数"<<endl;
cout<<"我希望显示的是子类"<<endl;
oneshape.fun();
}
多看看书
main()前加; {draw();};
}加;
--------------------Configuration: 1 - Win32 Debug--------------------
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.1.exe - 2 error(s), 0 warning(s)
重新建一个项目文件夹---》打开vc,点项目---》‘控制台应用程序’(你可能选择的是‘应用程序’,应选择它下面那一项)---》ok---》空文件工程---》添加一个c++源文件---》将原来的代码复制到这个文件中(记住去掉#include "stdafx.h"哟)---》执行!
去掉,就好了!谢谢!马上结贴!额外的问题:
有哪位朋友能够告诉我,如何用VC++6.0编辑和调试C或者C++程序???
我明明已经结贴,怎么没有存上!气我!