The syntax to use depends on what you are trying to accomplish. As it stands, it is not clear if there is a syntax error or a logical error.
Here is what the current syntax says to do (skipping some irrelevant steps):
- Create an array of pointers (these pointers are garbage initially).
- Assign a value to the object pointed to by the first of these pointers (but since the pointer contains garbage, dereferencing it is an access violation).
You are missing the step where the pointer is assigned a valid value. If the intent is to point to siteCloud
, Killzone Kid's answer is the way to go (ptrTest[0] = &siteCloud;
I am not going to advocate using a double underscore). If the intent is to copy the values from siteCloud
to the object pointed to by the array element, you need to create that object first (something like ptrTest[0] = new EstablishmentCloud_site
).
The former method (assigning addresses) can run into problems if the objects do not have a sufficiently long lifespan. The latter method (more allocations) can run into memory leaks if you do not adequately clean up afterwards. If either of these are problems in your situation, you may want to reconsider if you really want an array of pointers. (You might find that there are standard templates that can make your implementation easier.)