c++ - 公共(public)继承类无法访问基类的重载非虚拟公共(public)方法?

标签 c++ inheritance overloading

我的编译器说:

error C2660: 'UberMaterial::Initialize' : function does not take 2 arguments

当我写这篇文章时:

#include "BaseMaterial.h"
#include "UberMaterial.h"

UberMaterial* m_pGameLevelMaterial;
m_pGameLevelMaterial->Initialize(m_pContentManager, m_pLevel->GetDevice());

基类:

class BaseMaterial
{
public:
BaseMaterial(tstring shaderFilename);
virtual ~BaseMaterial(){}

void Initialize(ContentManager *pContentManager, ID3D10Device *pD3DDevice);
//[More Code...]

protected:
    virtual void Initialize(ContentManager *pContentManager) = 0;
//[More Code...]
};

继承类:

#include "BaseMaterial.h"
class UberMaterial:public BaseMaterial
{
//[More Code...]
protected:
    virtual void Initialize(ContentManager *pContentManager);
//[More Code...]
};

谁能告诉我问题出在哪里?

如果您需要更多代码,请发表评论,我会发布。但是整个事情相当大,所以我现在没有把它包括在内。

最佳答案

是的,默认情况下,派生类中的重载将隐藏与基类不同的重载。您可以使用 using 重新公开基类重载:

class UberMaterial : public BaseMaterial
{
    ...

public:
    using BaseMaterial::Initialize;

    virtual void Initialize(ContentManager *pContentManager);
};

关于c++ - 公共(public)继承类无法访问基类的重载非虚拟公共(public)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8662809/

相关文章:

c++ - 尝试使用 stringstream 将字符串转换为 int

c++ - 我如何在 Qt Creator 的主窗口中声明对象?

C++:重叠基类方法

java - java重载方法的搜索顺序

c++ - 如何为用 C++ 模板编写的库制作封闭源代码

c++ - 通过 Visual C++ 通过 UDP 发送得到大量未解析的外部符号 __imp__sendto@24

C++,继承与多态

java - 如何避免警告 : return type requires unchecked conversion?

c# - 在派生类中隐藏基类的公共(public)属性

python - 如何重写两个相互调用的方法,同时使用 super() 访问基类方法?