#include <iostream>
class B {
protected:
const int a_;
int b_;
B (int b, int a) : a_(a), b_(b) {}
public:
operator bool () const { return b_ == a_; }
};
class D1 : public B {
public:
D1 (int b = 0, int a = 0) : B(b, a) {}
operator int () const { return b_; }
};
class D2 : public B {
public:
D2 (int b = 0, int a = 0) : B(b, a) {}
operator const int & () const { return b_; }
};
int main () {
if (const D1 d1a = D1('a', 'a')) std::cout << "d1a\n";
if (const D1 d1b = D1('b', 'a')) std::cout << "d1b\n";
if (const D2 d2a = D2('a', 'a')) std::cout << "d2a\n";
if (const D2 d2b = D2('b', 'a')) std::cout << "d2b\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgogCmNsYXNzIEIgewpwcm90ZWN0ZWQ6CiAgICBjb25zdCBpbnQgYV87CiAgICBpbnQgYl87CiAgICBCIChpbnQgYiwgaW50IGEpIDogYV8oYSksIGJfKGIpIHt9CnB1YmxpYzoKICAgIG9wZXJhdG9yIGJvb2wgKCkgY29uc3QgeyByZXR1cm4gYl8gPT0gYV87IH0KfTsKIApjbGFzcyBEMSA6IHB1YmxpYyBCIHsKcHVibGljOgogICAgRDEgKGludCBiID0gMCwgaW50IGEgPSAwKSA6IEIoYiwgYSkge30KICAgIG9wZXJhdG9yIGludCAoKSBjb25zdCB7IHJldHVybiBiXzsgfQp9OwogCmNsYXNzIEQyIDogcHVibGljIEIgewpwdWJsaWM6CiAgICBEMiAoaW50IGIgPSAwLCBpbnQgYSA9IDApIDogQihiLCBhKSB7fQogICAgb3BlcmF0b3IgY29uc3QgaW50ICYgKCkgY29uc3QgeyByZXR1cm4gYl87IH0KfTsKIAppbnQgbWFpbiAoKSB7CiAgICBpZiAoY29uc3QgRDEgZDFhID0gRDEoJ2EnLCAnYScpKSBzdGQ6OmNvdXQgPDwgImQxYVxuIjsKICAgIGlmIChjb25zdCBEMSBkMWIgPSBEMSgnYicsICdhJykpIHN0ZDo6Y291dCA8PCAiZDFiXG4iOwogICAgaWYgKGNvbnN0IEQyIGQyYSA9IEQyKCdhJywgJ2EnKSkgc3RkOjpjb3V0IDw8ICJkMmFcbiI7CiAgICBpZiAoY29uc3QgRDIgZDJiID0gRDIoJ2InLCAnYScpKSBzdGQ6OmNvdXQgPDwgImQyYlxuIjsKICAgIHJldHVybiAwOwp9