我做了一个Ado调用access数据库的简单小例子,自定义了一个数据类,我想在CXXview里显示出几个我想要的结果。所以我选默认的CView.
   在程序调试的时候出现了这样的问题,GetDocument()报语法错,而且重复报错,他不认我的CXXDoc,即使我把CXXDoc的头文件也包了进来。  
   因为CXXDoc是从CDocument继承而来的, 我将CXXDoc该为了CDocument, 试试看,结果编译通过,但程序运行不通过, “OX004020b28"指令引用的“0xcdcdcdcd"内存。该内存不能为“read".
   这是什么原因呢?希望各位能不吝赐教。

解决方案 »

  1.   

    如果写的正确,是不需要CXXDOC.H文件的
      

  2.   

    GetDocument()报语法错是你的GetDocument()函数不认你的CXXDoc,那要看你的VIEW类了
      

  3.   

    把# include "CMyDoc.h"在CMyView.h"类里面声明,尽量放在
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif 之前,如果还有错误,检查一下内联函数是否有错误,我碰见过这样的问题,最后就是这样解决了
      

  4.   

    是不是你在其他类中引用了CVIEW类中的某个函数或者变量?如果是的话,因为它的构造函数是private的,引用的时候会出现问题,提示GetDocument()报错,你如果把它改成public型的,同时加入CXXDoc头文件应该是可以的
      

  5.   

    报措是这样的:
    (23) : error C2143: syntax error : missing ';' before '*'
    (23) : error C2501: 'CCcdDoc' : missing storage-class or type specifiers
    (23) : error C2501: 'GetDocument' : missing storage-class or type specifiers
    ccdView.cpp(109) : error C2556: 'class CCcdDoc *__thiscall CCcdView::GetDocument(void)' : overloaded function differs only by return type from 'int *__thiscall CCcdView::GetDocument(void)'
    error C2371: 'GetDocument' : redefinition; different basic type
    (23) : error C2143: syntax error : missing ';' before '*'
    (23) : error C2501: 'CCcdDoc' : missing storage-class or type specifiers
    (23) : error C2501: 'GetDocument' : missing storage-class or type specifiers。
    qqhuangshen: 我试了一下,还是不行。以下是我的Doc 和 View 的头文件和部分实现文件, 希望各位再帮我看看。Doc 的头文件
    #include "stdafx.h"
    #include "ccd.h"#include "MainFrm.h"
    #include "ccdDoc.h"
    #include "ccdView.h"
    #include "SampleRs.h"  //recordset
    class CCcdDoc : public CDocument
    {
    public: // create from serialization only
    CCcdDoc();
    virtual ~CCcdDoc();
    DECLARE_DYNCREATE(CCcdDoc)// Attributes
    public:
    // Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CCcdDoc)
    public:
    virtual BOOL OnNewDocument();
    virtual void Serialize(CArchive& ar);
    virtual void DeleteContents();
    //}}AFX_VIRTUAL// Implementation
    public:
    CString * DisplayRcd();
    CSampleRs* GetRecSet();
    void GenerateError(HRESULT hr,PWSTR pwszDescription);#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
    #endifprotected:
    _RecordsetPtr m_pRs;
    IADORecordBinding* m_piAdoRecordBinding;
    CString m_strConnection; 
    CString m_strCmdText; CSampleRs m_rsRecSet; CString ss;
    // Generated message map functions
    protected:
    //{{AFX_MSG(CCcdDoc)
    // NOTE - the ClassWizard will add and remove member functions here.
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };/////////////////////////////////////////////////////////////////////////////////View 的头文件:#include "StdAfx.h"
    #include "ccdDoc.h"
    #include "SampleRs.h"#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000class CCcdView : public CView
    {
    public: // create from serialization only
    CCcdView();
    DECLARE_DYNCREATE(CCcdView)// Attributes
    public:
    CCcdDoc* GetDocument();//     2// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CCcdView)
    public:
    virtual void OnDraw(CDC* pDC);  // overridden to draw this view
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    protected:
    virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CCcdView();
    #ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
    #endifprotected:// Generated message map functions
    protected:
    //{{AFX_MSG(CCcdView)
    // NOTE - the ClassWizard will add and remove member functions here.
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };#ifndef _DEBUG  // debug version in ccdView.cpp
    inline CCcdDoc* CCcdView::GetDocument()
       { return (CCcdDoc*)m_pDocument; }
    #endif///////////////////////////////////////////////////////////////////////////////View的实现文件:(部分)
    #include "stdafx.h"
    #include "ccd.h"#include "ccdDoc.h"
    #include "ccdView.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endifCCcdDoc* CCcdView::GetDocument() // non-debug version is inline
    {
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCcdDoc)));
    return (CCcdDoc*)m_pDocument;
    }
      

  6.   

    yzhouen: 我其他地方没有用到view类里的东西。不过谢谢你的建议。:)
      

  7.   

    你在ccdView.h中包含ccdDoc.h,而在ccdDoc.h中包含ccdView.h。这是循环包含。有问题啊。
      

  8.   

    在cpp中互相包含没问题
    头文件中如果只是使用指针,那么不用包含相应头文件,只用声明一下就可以了
    class CMydoc;
    class CMyView
    {
    CMyDoc* GetDocument();
    }在cpp中调用GetDocument()之前包含CMydoc的定义头文件就行了
    反之对doc中调用view的处理也一样