Pointer(s)

M

Michael Sgier

Hi
why is he using such pointers? Why pointers anyway? Wouldn't there be a
more simple way to do such?
Thanks Michael


/// Pointer to array of pointers to cameras in the scene.
fCamera** m_parrpCameras;
 
V

Victor Bazarov

Michael said:
why is he using such pointers? Why pointers anyway? Wouldn't there be a
more simple way to do such?
Thanks Michael


/// Pointer to array of pointers to cameras in the scene.
fCamera** m_parrpCameras;

If the class (since this is a member) does not *create* the collection
of the cameras, it does make sense to have the member as a pointer to
that collection. The collection is apparently a simple array (most
likely dynamically allocated). Every element of the collection is a
pointer to a camera (most likely to provide polymorphic behaviour).
Hence the member is a pointer to a pointer.

Another solution would be a reference or a pointer to a vector of
pointers to cameras, like so

std::vector<fCamera*>& m_rVpCameras;

or

std::vector<fCamera*>* m_pVpCameras;

If the class wants to assume ownership for those elements, it could
declare the member to be a plain vector (and not a pointer to it), like
here:

std::vector<fCamera*> m_vpCameras;

Anyway, the explanation is most likely in the same place where you got
your snippet. Asking us to speculate is not the best course of action
if you want to figure something out about the code you have.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top