Hi folks,

In the following code, I have passed an object by reference to a function. I have attempted to protect the object by using the const parameter. But I can still destroy the object (through a pointer to it). How do I protect against this ? I know the code is strange - but it is valid for the vehicle class to wish to have a data member (ptrperson) pointing to the incoming object.

class person
{
public :
int age;
};

class vehicle
{
public :
person *ptrperson;
void destroy(const person & refperson);

};

void vehicle:estroy(const person& refperson)
{
*ptrperson = refperson;
ptrperson->age++; // I don't like this - but it's legal !
delete ptrperson; // I like this evne less - but it too is legal !
}

void main (void)
{
person me;
vehicle car;
car.destroy(me);
}