C++ override/overload problem

后端 未结 1 449
野趣味
野趣味 2020-12-10 15:46

I\'m facing a problem in C++ :

#include 

class A
{
protected:
  void some_func(const unsigned int& param1)
  {
    std::cout << \"         


        
相关标签:
1条回答
  • 2020-12-10 16:15

    The problem is that in the derived class you are hiding the protected method in the base class. You can do a couple of things, either you fully qualify the protected method in the derived object or else you bring that method into scope with a using directive:

    class B : public A
    {
    protected:
      using A::some_func; // bring A::some_func overloads into B
    public:
      virtual ~B() {}
      virtual void some_func(const unsigned int& param1, const char*)
      {
        A::some_func(param1); // or fully qualify the call
      }
    };
    
    0 讨论(0)
提交回复
热议问题