Operator overloading.

Just as some fun I was trying to implement the std::string class. I've not really used operator overloading before but I'm confused about why the following (the only operator overloading function) code:

1
2
3
4
5
6
7
8
 void MyString::operator=(MyString rhs)
{
	delete[] str;
	str = rhs.str;

	//std::cout<<std::endl<<" xxx\n";
}


accepts input which is a string literal:

1
2
MyString teststr;
teststr = "dog";


Why is this function executing when the operator overloading function only accepts the MyString class as an operator?

Thanks!
your MyString probably has a converting constructor from const char *. Implicit conversions are performed in function calls.
Topic archived. No new replies allowed.