I'm having a problem accessing member functions through a manager array. In this example, I have 3 different types of guns that inherit from a base class. I'm getting a problem when the output function tries to access my virtual output function.
Array indices go from 0 to size-1 where size is the number of elements in the array. Therefore, if an array has size 10 a for loop that visits all elements would look like:
1 2
for ( unsigned i=0; i<10; ++i )
visit(Array[i]) ;
and not
1 2
for ( unsigned i=1; i<=10; ++i )
visit(Array[i]) ;
The gun type "pistol" takes an argument in it's output function. Why isn't one supplied to it in manager::output? Is it a virtual function in the gun type base class definition? Do the signatures match in the derived classes?
... that does nothing. And your derived class doesn't override it (the signatures are not the same -- that's overloading, not overriding) so you get the base class behavior.
Class methods have a pointer to the invoking object passed implicitly in the form of the this pointer. There is no reason for the reload method to take an explicit argument.
I ended up being able to not use any arguments to get everything done. Thanks for all the help. but just so I know, is it possible to pass new objects into functions?