一个特别奇怪的问题为什么我用新建一个MFC EXE时,如果最后一步选择VIEW的基类为CView,则当我用classWizard New一个class选择这个新的class的基类为CListView或是CTreeView时,就会出错啊?错误如下:其中temp1就是我用classWizard新加的类,基类为CTreeView
f:\sample\temp\temp1.h(14) : error C2504: 'CTreeView' : base class undefined
F:\sample\temp\temp1.cpp(17) : error C2440: 'return' : cannot convert from 'class temp1 *' to 'class CObject *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
F:\sample\temp\temp1.cpp(17) : error C2653: 'CTreeView' : is not a class or namespace name
F:\sample\temp\temp1.cpp(17) : error C2065: 'classCTreeView' : undeclared identifier
F:\sample\temp\temp1.cpp(28) : error C2653: 'CTreeView' : is not a class or namespace name
F:\sample\temp\temp1.cpp(39) : error C2065: 'GetDocument' : undeclared identifier
F:\sample\temp\temp1.cpp(39) : error C2440: 'initializing' : cannot convert from 'int' to 'class CDocument *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
F:\sample\temp\temp1.cpp(49) : error C2653: 'CTreeView' : is not a class or namespace name
F:\sample\temp\temp1.cpp(54) : error C2653: 'CTreeView' : is not a class or namespace name
但是如果我新建MFC EXE,最后一步选择CTreeView时,再做同样的操作却没有任何错误。请哪位大侠指点一下,不甚感激。

解决方案 »

  1.   

    在StdAfx.h中包含入#include "afxcview.h"后,就不会出错了。
      

  2.   

    看msdn
    CTreeView
    The CTreeView class simplifies use of the tree control and of CTreeCtrl, the class that encapsulates tree-control functionality, with MFC’s document-view architecture. For more information on this architecture, see the overview for the CView class and the cross-references cited there.#include <afxcview.h>Class Members |  Base Class |  Hierarchy ChartSample   MFC Sample DBFETCHSee Also   CView, CCtrlView, CTreeCtrl
    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources. 这个treeview必须包含"afxcview.h"头文件