Есть такой код:
#include <iostream>
using std::cout;
using std::endl;
class str{
public:
str(const char* ttext){
size = sizeof(ttext);
text = new char[size];
text = (char*)ttext;
}
char* text;
int size;
char operator[](int i){
if(i<size){
return text[i];
}
else{
cout<<"123123"<<endl;
return 0;
}
}
};
int main(int argc, char* argv[]){
str* s = new str("Hello");
cout<<s->text[5]<<endl;
cout<<s->size<<endl;
return 0;
}
Итак, почему sizeof возвращает 8, ведь символов всего 5. Даже если принять в расчет нулевой символ, будет 6 но никак не 8. Почему sizeof выводит не то?