#include <iostream>
using namespace std;
class BClass
{
private:
const char code; //how to make const?
public:
BClass(char c) : code(c) {}
char getCode() const { return code; }
};
class AClass
{
private:
const BClass b0; //how to make const?
const BClass b1; //how to make const?
const BClass* bPtrs[2];//how to make const?
public:
AClass() : b0('x'), b1('y')
{
bPtrs[0] = &b0;
bPtrs[1] = &b1;
}
void print(int i) const
{
cout << "char=" << bPtrs[i]->getCode() << endl;
}
};
AClass a;
int main()
{
a.print(0); // prints "char=x"
a.print(1); // prints "char=y"
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgQkNsYXNzCnsKcHJpdmF0ZToKICAgIGNvbnN0IGNoYXIgY29kZTsJLy9ob3cgdG8gbWFrZSBjb25zdD8KcHVibGljOgogICAgQkNsYXNzKGNoYXIgYykgOiBjb2RlKGMpIHt9CgogICAgY2hhciBnZXRDb2RlKCkgY29uc3QgeyByZXR1cm4gY29kZTsgfQp9OwoKY2xhc3MgQUNsYXNzCnsKcHJpdmF0ZToKICAgIGNvbnN0IEJDbGFzcyBiMDsJLy9ob3cgdG8gbWFrZSBjb25zdD8KICAgIGNvbnN0IEJDbGFzcyBiMTsJLy9ob3cgdG8gbWFrZSBjb25zdD8KICAgIGNvbnN0IEJDbGFzcyogYlB0cnNbMl07Ly9ob3cgdG8gbWFrZSBjb25zdD8KcHVibGljOgogICAgQUNsYXNzKCkgOiBiMCgneCcpLCBiMSgneScpCiAgICB7CiAgICAgICAgYlB0cnNbMF0gPSAmYjA7CiAgICAgICAgYlB0cnNbMV0gPSAmYjE7CiAgICB9CgogICAgdm9pZCBwcmludChpbnQgaSkgY29uc3QgCiAgICB7CiAgICAgICAgY291dCA8PCAiY2hhcj0iIDw8IGJQdHJzW2ldLT5nZXRDb2RlKCkgPDwgZW5kbDsKICAgIH0KfTsKQUNsYXNzIGE7CgppbnQgbWFpbigpCnsKICAgIGEucHJpbnQoMCk7IC8vIHByaW50cyAiY2hhcj14IgogICAgYS5wcmludCgxKTsgLy8gcHJpbnRzICJjaGFyPXkiCn0=