0

I'm curious as to why a protected overload of a function is being invoked as opposed to the publicly declared other. Here is what I have defined in my header files.

// A.h
class A
{
public:
  virtual void Foo() { Foo(true); }
  virtual void Init() = 0; // unrelated
protected:
  A() {}
  virtual void Foo(bool bar); // implemented in A.cpp
}

// B.h
#include "A.h"
class B : public A  // no mention of function Foo()
{
protected:
  B() {}
}

// C.h
#include "B.h"
class C : public B
{
public:
  C() {}
  void Init(); // defined in C.cpp
protected:
  void Foo(bool bar); // defined in C.cpp
}

In my main.cpp I have the following:

#include <iostream>
#include "C.h"

int main(int argc, char* argv[])
{
  C obj;
  obj.Init();

  obj.Foo();
  return 0;
}

Upon compiling, I get these errors:

'C::Release': function does not take 0 arguments
"C::Release" (declared at line X of "C.h") is inaccessible

It's been awhile since I worked with OOP so forgive me if it's (likely) a stupid omission. But shouldn't the virtual void Foo() declared in class A be inherited by class C by default?

Thanks

A1693
  • 44
  • 6
  • Thanks Raymond, that did the trick :) .. P.S. I've referred to your blogs on msdn more times than I can recount – A1693 Feb 01 '23 at 22:07

0 Answers0