B
Bill97
In my code below, the conversion operator is invoked implicitly (and
explicitly) in main(). In the first case, the address value is output--in
the later cases the character string pointed to by the address is output.
I am looking for a satisfying answer as to why the character string isn't
output in the first of the 3 cases? Thank you for your reply
class String
{
public:
String(char * s)
{
strcpy(A, s);
}
operator char *()
{
cout << "conv. op. called" << endl;
return A;
}
private:
char A[100];
};
int main()
{
String pet("cat");
cout << pet << endl;
cout << (( char *)pet) << endl;
cout << static_cast< char *>(pet) << endl;
return 0;
}
explicitly) in main(). In the first case, the address value is output--in
the later cases the character string pointed to by the address is output.
I am looking for a satisfying answer as to why the character string isn't
output in the first of the 3 cases? Thank you for your reply
class String
{
public:
String(char * s)
{
strcpy(A, s);
}
operator char *()
{
cout << "conv. op. called" << endl;
return A;
}
private:
char A[100];
};
int main()
{
String pet("cat");
cout << pet << endl;
cout << (( char *)pet) << endl;
cout << static_cast< char *>(pet) << endl;
return 0;
}