lets say i have an array of pointers to a list or a queue, and the list items that i insert in that list or queue are class object. So how would i go about accessing functions from the class object through the pointer in the array.
class example
{
private:
int number;
public:
example();
void setNumber();
int getNumber();
};
int main()
{
queue* exArray[];
for (int x = 0; x < size; x++)
{
exArray[x] = new queue;
}
// access setNumber() from array of queue, for which
// example object is being inserted into.
// how do i do this ?
return 1
}
Well, when you access the array, the operator[] will return a pointer. You can treat that returned pointer like any other pointer. So to call a function using that pointer use the -> operator.
i know how to use the functions from the list or queue im adding to, but im asking how would i access the functions from the example class(ie. the object im adding to that list) from that array? thanks.
Ok, well it's basically the same idea, but if the queue returns a pointer you need to use the -> operator and if the queue returns a reference or value then you need to use the . (dot) operator.
1 2 3 4 5
//pointer
exArray[someIndex]->get()->someFunction();
//reference or value
exArray[someIndex]->get().someFunction();