R
Radde
Hi,
class String
{
public:
String(char* str);
void operator char*();
private:
char* data;
};
String::String()
{
if(str)
data = new char[strlen(str)+1];
strcpy(data, str);
}
};
operator char*()
{
return data;
}
void main()
{
string s1("HIHI");
const char* mystr = s1; //
}
One thing i want ask from above is
const char* mystr = s1; // s1.operator char*() gets called..
I really dont undertand, whats mechanism behind it..How does it
simplify to s1.operato char*()..
I know operator=() which takes one parameter as refernce and returns
reference object i.e
String& operator=(const String& s1);
suppose when we call
String s1("HII");
String s2("Hello");
s2 = s1, then it simplify to s2.operator=(s1)..
Similarly how does the above operator char*() works..i mean how is the
simplification done..
Cheers..
class String
{
public:
String(char* str);
void operator char*();
private:
char* data;
};
String::String()
{
if(str)
data = new char[strlen(str)+1];
strcpy(data, str);
}
};
operator char*()
{
return data;
}
void main()
{
string s1("HIHI");
const char* mystr = s1; //
}
One thing i want ask from above is
const char* mystr = s1; // s1.operator char*() gets called..
I really dont undertand, whats mechanism behind it..How does it
simplify to s1.operato char*()..
I know operator=() which takes one parameter as refernce and returns
reference object i.e
String& operator=(const String& s1);
suppose when we call
String s1("HII");
String s2("Hello");
s2 = s1, then it simplify to s2.operator=(s1)..
Similarly how does the above operator char*() works..i mean how is the
simplification done..
Cheers..