VC技术内幕第5版第24章,组件对象模型的示例EX24B在Spaceship.h文件中的一段代码:
BEGIN_INTERFACE_PART(Visual,IVisual)
   STDMETHOD_(void,Display)();
END_INTERFACE_PART(Visual)BEGIN_INTERFACE_PART(Motion, IMotion)
   STDMETHOD_(void, Fly) ();
   STDMETHOD_(int&, GetPosition) ();
END_INTERFACE_PART(Motion)编译的时候提示
error C2504: 'IVisual' : base class undefined
error C2504: 'IMotion' : base class undefined看书中的代码,那两个接口是在interface.h文件中定义的struct IVisual:public IUnknown
{
STDMETHOD_(void,Display)()=0;
};
struct IMotion : public IUnknown
{
    STDMETHOD_(void, Fly) () = 0;
    STDMETHOD_(int&, GetPosition) () = 0;
};而只在Spaceship.cpp文件中有过#include“interface.h”实在搞不懂那两个接口是在哪里定义的,请各位指点一下,多谢了!!

解决方案 »

  1.   

    Requirements 
      Windows NT/2000/XP: Requires Windows NT 3.1 or later.
      Windows 95/98: Requires Windows 95 or later.
      Header: Declared in unknwn.h.你只需要
    #include <afxole.h>
    就可以了
      

  2.   

    我是要在interface.h中#include <afxole.h>吗?
      

  3.   

    yes
    在interface.h中#include <afxole.h>
    !
      

  4.   

    可是在工程中的stdafx.h文件中已有包含afxole.h了啊,我在在interface.h中#include <afxole.h>,仍然提示上述错误而且技术内幕的源码光盘中,在interface.h中也没有#include <afxole.h>的代码,它仍然能编译通过实在不解#ifndef _AFX_NO_OLE_SUPPORT
    #include <afxole.h>         // MFC OLE classes
    #include <afxodlgs.h>       // MFC OLE dialog classes
    #include <afxdisp.h>        // MFC Automation classes
    #endif // _AFX_NO_OLE_SUPPORT