(*this) pointer

class myString {
....
....
void format( const char *fmt, ... )
{
char buffer[ 10240 ];
va_list alist;
va_start(alist, fmt );
vsprintf( buffer, fmt, alist );
(*this) = buffer;
}
...
...
};

I don't understand the last line; (*this) = buffer

I know the this pointer using like below

class A
{
...
...
A example()
{
...
...
return *this;
}
...
...
};

I haven't seen the first example.
Could you please explain it "(*this) = buffer" in details?
Let a is an object of class A. In this case *this is equivalent to a. So in the example you showed there is an assignmnet a = buffer.

Thus in class myString there shall be declaration similar to the following

myString & operator =( const char * );
Last edited on
Topic archived. No new replies allowed.