Q:

Printing a dynamic array of objects using an overloaded operator << in c++

I need to print out a bunch of Objects from a dynamic array using the overloaded << operator.
I've overloaded the << operator this way:
ostream& operator<<(ostream& os, Person* dt)
{
    return os << dt->getName();//getName returns a char*
}

Now this works just fine with regular pointers, however as soon as I try doing something like this:
    Person *p = new Person("Dany", 4);
    Object** obj=new Object*[sizeof(p)];
    obj[0] = p;
    cout << obj << endl;

I get a meaningless value. 
Keep in mind the Person class is a derivative of the abstract Object class.

A:

the problem is that a person is an object(according to you, we can get philosophical about it but ok) and so he have access to all of the protected and public methods of an object. but an object is not a person so it dos not know how to use methods defined in person(such as the operator).
you can directly convert a person to an object, as you did. but not an object to a person, like you tried to imply.
usually one will use a virtual function to produce the behavior you are looking for but as you said this it tricky, because operator<< is a friend function and thous cannot be virtual. luckily a nice technique to make << virtual was posted some time ago.

