我用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();
}

解决方案 »

  1.   

    class name
    {
        ...
    };  <--分号
      

  2.   

    // 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()
       {
    circle oneshape;
    cout<<"这个例子是在学习C++的多态性"<<endl;
    cout<<"动态联编:虚函数"<<endl;
    cout<<"我希望显示的是子类"<<endl;
    oneshape.fun();
    }
    多看看书
      

  3.   

    class circle oneshape;改为circle oneshapeoneshape.fun()后加 return 0;
    main()前加; {draw();};
    }加;
      

  4.   

    分号;我已经加上,可是还有问题呀?请再指教一下吧!谢谢
    --------------------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)
      

  5.   

    这样试一试
    重新建一个项目文件夹---》打开vc,点项目---》‘控制台应用程序’(你可能选择的是‘应用程序’,应选择它下面那一项)---》ok---》空文件工程---》添加一个c++源文件---》将原来的代码复制到这个文件中(记住去掉#include "stdafx.h"哟)---》执行!
      

  6.   

    huwei_008(胡一刀)你好!我受你的启发,直接将程序中的#include "stdafx.h"
    去掉,就好了!谢谢!马上结贴!额外的问题:
    有哪位朋友能够告诉我,如何用VC++6.0编辑和调试C或者C++程序???
      

  7.   

    我也一并回答了吧重新建一个项目文件夹---》打开vc,点文件---》c/c++source file-->文件名处填“你的源程序名.c”既编辑c程序,只填“你的源程序名”,默认为编辑c++程序
      

  8.   

    谢谢huwei_008(胡一刀)大侠!棒极了!
    我明明已经结贴,怎么没有存上!气我!