Can't override CMemFile::GrowFile
I have a class derived from CMemFile called TempMemFile. I need to but can't 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
}
Your GrowFile
implementation is for a global function called GrowFile
. You need CTempMemFile::
in front of the implementation.
void CTempMemFile::GrowFile(SITE_T dwNewLen)
{
}
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).
精彩评论