rstackhouse
rstackhouse

Reputation: 2326

Trying to override CView::OnUpdate in CFormView

I am working on an SDI project where the View inherits CFormView. I am trying to override CView::OnUpdate, but the compiler complains like so:

'CMyFormView::OnUpdate' : 'virtual' storage-class specifier illegal on function     

definition

Here's my class definition:

class CMyFormView : public CFormView
{
…
// Overrides
public:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    virtual void OnInitialUpdate(); // called first time after construct
    virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
};

The function I'm trying to override looks like this:

virtual void CMyFormView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
    CFormView::OnUpdate(pSender, lHint, pHint);

    //Get the current data from our document
    CMyAppDoc* pDoc = GetDocument();
} 

Could someone please tell me how to fix this?

Upvotes: 1

Views: 1039

Answers (1)

Joseph Willcoxson
Joseph Willcoxson

Reputation: 6040

Don't put "virtual" in the function definition (the .cpp file). You can put it only in the declaration (.h file). If it is already declared virtual in the base class hierarchy (CView?), then you don't need the "virtual" keyword at all since it will automatically be virtual if you have the same function declaration.

Upvotes: 3

Related Questions