我插入了一个基类是CTreeView的类CLeft,并且照例子在stdafx.h中加入"#include <afxcview.h>"这条语句,可编译时提示left.h中的定义类语句"class CLeft : public CTreeView"这一行出错,提示信息为:error C2504: 'CTreeView' : base class undefined。请问是怎么回事,该如何解决?

解决方案 »

  1.   

    make sure you include "stdafx.h" first in your cpp file.
      

  2.   

    jiangsheng:Left.cpp中加入了确实有 #include "stdafx.h"这条语句呀,可编译时就时提示像我说的那样的错误呀!
      

  3.   

    跟踪到CTreeView的定义的地方看看有什么问题先
      

  4.   

    在stdafx.h 或者该left.cpp中包含
    #include <Afxcview.h>
      

  5.   

    楼主,把这个#include <afxcview.h>写到你的Left.h的开始部分就可以了.因为你先前把#include <afxcview.h>写到stdafx.h中,但是stdafx.h是包含在Left.cpp中的,所以会报错.
      

  6.   

    你的CTreeView是在Left.h中用到了,而不是Left.cpp,所以即使你在stdafx.h中包含了该基类的头文件,但是不会在Left.h中起作用,因为stdafx.h是包含在Left.cpp中的.
      

  7.   

    #if !defined(AFX_LEFT_H__4914483C_1ED3_4685_9625_11CCD41B456F__INCLUDED_)
    #define AFX_LEFT_H__4914483C_1ED3_4685_9625_11CCD41B456F__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // Left.h : header file
    //
    #include <afxcview.h>
    /////////////////////////////////////////////////////////////////////////////
    // CLeft viewclass CLeft : public CTreeView
    {
    protected:
    CLeft();           // protected constructor used by dynamic creation
    DECLARE_DYNCREATE(CLeft)
    后面部分不写了,看见#include <afxcview.h>写的地方就行了,我亲自编译通过了.VC6.0
      

  8.   

    #include <afxcview.h> is not needed if you include it in your stdafx.h and stdafx.h is included in all source files and is always the first.
      

  9.   

    try
    class CTreeView;
    public left :CTreeView
    {};
      

  10.   


    #include <afxcview.h> is not needed if you include it in your stdafx.h and stdafx.h is included in all source files and is always the first.
      

  11.   

    很显然,楼主没有在stdafx.h里包含该头文件