无法覆盖 CMemFile::GrowFile
我有一个从 CMemFile 派生的类,称为 TempMemFile。我需要但无法重写 TempMemFile 中的 Growfile 方法。
当我在派生类 (TempMemFile) 中手动编写 GrowFile 方法时,当我单击 TempMemFile > 时,它永远不会被调用,并且在类视图中。属性>重写Growfile,其他方法这里就不列出来了。事实上,只有 3 种方法被列为可重写的 Assert、Dump 和 Dump 方法。连载。 MSDN 明确指出该方法可以被重写。我错过了什么吗?
实施/声明
// 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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还要确保您的重写方法的可见性与基类的声明相匹配:
不正确
应该是
public
或protected
(无论CMemFile::GrowFile
) code> 将其声明为)。Also make sure that the visibility of your override method matches the declaration of the base class:
is incorrect
Should be
public
orprotected
(whateverCMemFile::GrowFile
declares it as).您的
GrowFile
实现用于名为GrowFile
的全局函数。您需要在实现前面使用CTempMemFile::
。Your
GrowFile
implementation is for a global function calledGrowFile
. You needCTempMemFile::
in front of the implementation.