Obtaining a view from anywhere problem

According to the MSDN library it is possible to obtain a pointer to your derived view from anywhere.
Basically using a function in your derived view such as..
static CMyView * GetView();
// obtain a view and performe checks
/// then return (cast)CView;


However when you include the views header file in the required location, e.g MainFrame || a Dialog class it comes up with 3 errors that i dont understand...
delview.h(21) : error C2143: syntax error : missing ';' before '*'
delview.h(21) : error C2501: 'CDelDoc' : missing storage-class or type specifiers
delview.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers

However i can see no errors, and when i remove the include headers, there are no errors.. But i need to headers to access the view pointer.

Any Help much appreciated

JS

Comments

  • please post the content of your delview.h over here
  • here is view.h
    #if !defined(AFX_DELVIEW_H__65F3205F_3DE9_4C25_96FC_38F2E64C1D5F__INCLUDED_)
    #define AFX_DELVIEW_H__65F3205F_3DE9_4C25_96FC_38F2E64C1D5F__INCLUDED_

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000


    class CDelView : public CView
    {
    protected: // create from serialization only
    CDelView();
    DECLARE_DYNCREATE(CDelView)

    // Attributes
    public:
    CDelDoc* GetDocument();

    // Operations
    public:

    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDelView)
    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 ~CDelView();
    #ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
    #endif

    protected:

    // Generated message map functions
    protected:
    //{{AFX_MSG(CDelView)
    // 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 delView.cpp
    inline CDelDoc* CDelView::GetDocument()
    { return (CDelDoc*)m_pDocument; }
    #endif

    /////////////////////////////////////////////////////////////////////////////

    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

    #endif // !defined(AFX_DELVIEW_H__65F3205F_3DE9_4C25_96FC_38F2E64C1D5F__INCLUDED_)

  • : According to the MSDN library it is possible to obtain a pointer to your derived view from anywhere.
    : Basically using a function in your derived view such as..
    : static CMyView * GetView();
    : // obtain a view and performe checks
    : /// then return (cast)CView;
    :
    :
    : However when you include the views header file in the required location, e.g MainFrame || a Dialog class it comes up with 3 errors that i dont understand...
    : delview.h(21) : error C2143: syntax error : missing ';' before '*'
    : delview.h(21) : error C2501: 'CDelDoc' : missing storage-class or type specifiers
    : delview.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers
    :
    : However i can see no errors, and when i remove the include headers, there are no errors.. But i need to headers to access the view pointer.
    :
    : Any Help much appreciated
    :
    : JS
    :
    Could you be a little more specific about what you are trying to do.

    i.e why are you trying to access a view pointer and from where.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories