class car
{
private:
string carModel;
public:
car (string carModel);
~car (){}
string returnModel()
{
return (carModel);
}
};
car::car (string carMod): carModel(carMod)
{}
int main()
{
car*potential = new car ("Ferrari");
potential->returnModel();
}
//I've found that the following doesn't quite do as expected.
delete potential;
car*potential = new car ("Mercedes");
return 0;
}
OK, that needs some indenting.
I see now... you were making a dynamically allocated car, right?
So if you want to modify the class's data like that you could just create a member to modify the string member. Because the member is private you can't modify it directly but you could always form a member to get the job done.
Have you noticed that the delete code on line 28 is not in main?
After you delete potential (28) your pointer is still there, (just doesn't point to an allocated memory location), so don't redeclare potential, just give it a new value. : potential = new car ("Mercedes");