So I have the following class...
class Pet
{
public:
Pet() : id(0),
name("New Pet")
{
}
Pet(const int new_id, const std::string new_name) : id(new_id),
name(new_name)
{
}
Pet(const Pet new_pet) : id(new_pet.id),
name(new_pet.name)
{
}
private:
const int id;
const std::string name;
};
Somewhere in my code I then create a instance of this class like so...
Pet my_pet = Pet(0, "Henry");
Later on in my code, an event is supposed to cause this pet to be deleted. delete(my_pet);
How do I check if my_pet has been initialized...
Would something like this work?
if(my_pet == NULL)
{
// Pet doesn't exist...
}
my_pet
doesn't need to be deleted as it is non a dynamically allocated object. Do you meanPet* my_pet = new Pet(0, "Henry");
? – Jaridconst Pet
andconst std::string
arguments as reference, herePet(const Pet new_pet)
and herePet(const int new_id, const std::string new_name)
for efficiency, there's not a need to copy data here. – Expensive