These are not strange errors. They are caused by function overloads of the << operator.
For example, this code:
-
int testInt = 11;
-
int* Ptr = &testInt;
-
cout << *Ptr << endl << Ptr;
-
calls
ostream& operator<<(ostream&, int) to show 11
then
ostream& operator<<(ostream&, ostream& (*fp)(ostream&)) //to call endl function
then
ostream& operator<<(ostream&, int*) //to show address of int
Whereas this code:
-
char testChar = 'a';
-
char* Ptr = &testChar;
-
cout << *Ptr << " " << Ptr;
-
calls
ostream& operator<<(ostream&, char) //to show a
then for the " "
ostream& operator<<(ostream&, char*) //which ASSUMES a C-String
then
ostream& operator<<(ostream&, char*) //which ASSUMES a C-String
By my count you have called 5 different functions that do 5 different things but they all look like << to you. This is why function overloading inb C++ is called function polymorphism. It is a form of object-orient programming. Here trhe << operator "does the right thing".
Please desist with the casts. One cast destroys the type safety of your program. You cast in C++ if a) you are calling a relic C function and you have no choice, or b) your C++ design is screwed up.