I have this code but compilation failed:
class TextBlock
{
public:
TextBlock(std::string &s)
{
text = s;
}
private:
std::string text;
};
int main()
{
TextBlock tb("Hello");
std::cout<< tb[0] << std::endl ;
}
why when the constructor is TextBlock(const std::string &s)
the above code can compile success ?