#include "stdafx.h"
#include <iostream>#include <string>
using namespace std;
class TextBlock
{
public:
TextBlock(): text(""){}
TextBlock(const char t[]): text(t){}
TextBlock(const TextBlock& tb): text(tb.text)
{
}
~TextBlock(){}const char& operator[](std::size_t position) const
{
return text[position];
}
char& operator[](std::size_t position){return text[position];}
private:
std::string text;
};
int main(int argc, char* argv[])
{
TextBlock tb("Hello");
std::cout << tb[0]; //call non-const TextBlock::operator[]
const TextBlock ctb("World");
std::cout << ctb[0] << endl; //call const TextBlock::operator[]
return 0;
}