banner
cells

cells

为美好的世界献上 code

Q027

Q027#

#include <iostream>

struct A {
    virtual std::ostream &put(std::ostream &o) const {
        return o << 'A';
    }
};

struct B : A {
    virtual std::ostream &put(std::ostream &o) const override {
        return o << 'B';
    }
};

std::ostream &operator<<(std::ostream &o, const A &a) {
    return a.put(o);
}

int main() {
    B b;
    std::cout << b;
}

Answer#

click to see answer B
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.