Let’s say I have a function called dummy defined in the following way:
void dummy(CMyString& mystr)
{
mystr.print(); //show
}
CMyString would be my own implementation of strings using an array of chars.
int main()
{
dummy("This is a test!");
return 0;
}
I’d like the following program to print out : “This is a test!”.
Is this possible?
Yes it is, you just need to provide a non-
explicitconversion constructor toCMyString:and, of course, implement the
CMyString::printmethod. After this you need to change the parameter to(and mark the
printmethod asconst) because you can’t bind a temp to a non-const reference.