Sure.
Object Wall[10]; is an array of ten objects with indexs from zero to nine.
An array name is a pointer to the first element contained in that array, so if its the first wall you want to check then
obj_collision(&Ball,Wall); does the job.
If you want to check any of the other walls then you have two options
obj_collision(&Ball,Wall+index);
or
obj_collision(&Ball,& Wall[index]);
The first one uses the fact I just mentioned (array name == pointer) and adds the sizeof(Wall) to the pointer to get the next pointer. where as the second version uses the index to retreive the instance and then takes the address of it.
c++ inheritence newbie help
I don't want to bump this, but shouldn't he have made the base objects destructor virtual. I'm kind of surprised it compiled without it.
You shouldn't be. It's not required to make a destructor virtual (as far as compilation goes).
A destructor should be virtual if you intend for it to ever be called through a pointer to a base object that is actually a derived object (i.e., you delete a "Base*" that is currently pointing to a "Derived" instance).
If you can guarantee that you don't need runtime dispatch of the destructor, the destructor doesn't have to be virtual. You can argue that its good practice or not, but it is not required to compile.
A destructor should be virtual if you intend for it to ever be called through a pointer to a base object that is actually a derived object (i.e., you delete a "Base*" that is currently pointing to a "Derived" instance).
If you can guarantee that you don't need runtime dispatch of the destructor, the destructor doesn't have to be virtual. You can argue that its good practice or not, but it is not required to compile.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement