Hi people,
I am making a little experiment to see something. I wished to inherit "string" class and add a function to child class.
Function should take a char as parameter and return bool depending on is there such a character in our string or not.
I have started off with this, but I got stuck with "this":
class MyStringClass:public string{
public:
MyStringClass(const char* a):string(a){};
bool isInString(char);
};
bool MyStringClass::isInString(char s)
{
for(int i=0;i<=this->length();++i){
if(s==(*this)[i]) //here
return true;
}
return false;
}
this has type of MyStringClass*?
If so, why can't we access to its elements this way: this[i]?
I assumed so since if we made a pointer like:
int* a=new int;
a[0]=3;
Why wouldn't it work with this too?
MyStringClass* this;
this[0]=something