#include <iostream>
class Handle {
public:
Handle(): mValue(newValue()) {};
static const Handle kUndefHandle;
int value() const { return mValue; } // Added accessor for demonstration.
protected:
Handle(int val): mValue(val) {};
int mValue;
static int mNextValue;
static int newValue() { return mNextValue++; }
};
const Handle Handle::kUndefHandle(0);
int Handle::mNextValue = 1000;
class FakeHandle : public Handle
{
public:
FakeHandle(int val) : Handle(val) { }
};
int main() {
Handle bad = FakeHandle(5);
std::cout << bad.value() << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgSGFuZGxlIHsKcHVibGljOgogIEhhbmRsZSgpOiBtVmFsdWUobmV3VmFsdWUoKSkge307CgogIHN0YXRpYyBjb25zdCBIYW5kbGUga1VuZGVmSGFuZGxlOwogIAogIGludCB2YWx1ZSgpIGNvbnN0IHsgcmV0dXJuIG1WYWx1ZTsgfSAgLy8gQWRkZWQgYWNjZXNzb3IgZm9yIGRlbW9uc3RyYXRpb24uCgpwcm90ZWN0ZWQ6CiAgSGFuZGxlKGludCB2YWwpOiBtVmFsdWUodmFsKSB7fTsKICBpbnQgbVZhbHVlOwogIHN0YXRpYyBpbnQgbU5leHRWYWx1ZTsKCiAgc3RhdGljIGludCBuZXdWYWx1ZSgpIHsgcmV0dXJuIG1OZXh0VmFsdWUrKzsgfQp9OwoKY29uc3QgSGFuZGxlIEhhbmRsZTo6a1VuZGVmSGFuZGxlKDApOwoKaW50IEhhbmRsZTo6bU5leHRWYWx1ZSA9IDEwMDA7CgpjbGFzcyBGYWtlSGFuZGxlIDogcHVibGljIEhhbmRsZQp7CnB1YmxpYzoKCUZha2VIYW5kbGUoaW50IHZhbCkgOiBIYW5kbGUodmFsKSB7IH0KfTsKCmludCBtYWluKCkgewoJSGFuZGxlIGJhZCA9IEZha2VIYW5kbGUoNSk7CglzdGQ6OmNvdXQgPDwgYmFkLnZhbHVlKCkgPDwgc3RkOjplbmRsOwp9