理解这个C++代码.继承和范围更改

Raj*_*war 5 c++ oop inheritance interface interface-implementation

我在SO的一个帖子中看到了这个.我很难理解以下代码.

class A 
{
public:
    virtual void foo() = 0;
private:
    virtual void bar() = 0;
};

class B : public A 
{
private:
    virtual void foo() 
    {
        std::cout << "B in Foo \n";
    } 
public:
    virtual void bar() 
    {
        std::cout << "bar in Foo \n";
    } 
};

void f(A& a, B& b)
{
    a.foo(); // ok --->Line A
    //b.foo(); // error: B::foo is private
    //a.bar(); // error: A::bar is private
    b.bar(); // ok (B::bar is public, even though A::bar is private) --> Line B
}

int main()
{
    B b;
    f(b, b);
}
Run Code Online (Sandbox Code Playgroud)

现在我想知道A线是如何可能的?通常classA是一个接口,你将无法实例化它.您只能实例化其实现.如果有人能向我解释这里发生了什么,我将不胜感激.

更新:

是否有可能a在LineA中将其视为b的实现?