views:

60

answers:

2

I have a class derived from CMemFile called TempMemFile. I need to but cant override the Growfile method in TempMemFile.

When I hand write the GrowFile method in my derived class (TempMemFile) it is never called and In class view when I Click on my TempMemFile > Properties > Overrides the Growfile and other methods are not listed here. In fact only 3 methods are listed as override-able Assert, Dump & Serialize. MSDN specifically states that this method can be overridden. Am I missing something?

Implementation / Declaration

// TempMemFile.h

class CTempMemFile : public CMemFile

    {

    public:
        CTempMemFile(void);
        ~CTempMemFile(void);
        DWORD Begin(void);

    private:      
      void GrowFile(SIZE_T dwNewLen);  // override

    };

// TempMemFile.cpp

CTempMemFile::CTempMemFile(void) : CMemFile

    {   

    }

CTempMemFile::~TempMemFile(void)
    {

    }


void GrowFile(SIZE_T dwNewLen)

{

// This function is never called but CMemFile::Growfile always is verified on the callstack

}
+1  A: 

Your GrowFile implementation is for a global function called GrowFile. You need CTempMemFile:: in front of the implementation.

void CTempMemFile::GrowFile(SITE_T dwNewLen)
{
}
Aidan Ryan
Done that. Still exactly the Same.
Canacourse
+1  A: 

Also make sure that the visibility of your override method matches the declaration of the base class:

private:      
  void GrowFile(SIZE_T dwNewLen);  // override

is incorrect

Should be public or protected (whatever CMemFile::GrowFile declares it as).

dkackman
Done that. Still exactly the Same.
Canacourse
I took a peek at CMemFile and GrowFile is protected. This implies that it is called by the base class rather than called by a consumer. Do you know under what circumstances that base class needs to call GrowFile and are you sure that you are causing those circumstances? It could just be that this ptoected method is never being called.
dkackman