That array code will not work. There is no way to get the size of a dynamically allocated array, and static arrays cannot be resized. You can get the size of static arrays like so:
template <typename T, size_t N>
size_t arrayGetSize(T (&array)[N])
{
return N;
}
The only way to implement it would be to store both the array and its size together in a class. There would be quite a lot of code involved to write this, but luckily it has already been done for you. C++ has its own standard libraries, one of which is the Standard Template Library (STL). In the STL there is a "
std::vector<T>" class which is the closest thing to a DBPro array there is.
That contains methods to get the size of the vector, access elements at a particular index, add/remove elements, etc. If you look in the top right corner of that page, you can see it has the text "<vector>". This tells you the header file you need to include to use the class template, so in this case you would need to write:
Before you can use it in your code. Notice it uses angled brackets <> instead of double quotes "". This is not strictly necessary but makes the code more readable. Angled brackets are used for include files which are part of the standard library, as opposed to ones you've written yourself. Your code will compile faster too as the compiler can find the file more quickly.
edit:
Also, an explanation for why you were getting the shape error. The problem was that you were making an array of "Shape" when you wanted an array of "Shape*". In C++, dynamic arrays are just pointers, so when you wrote this:
Shape* shapes = new Shape[n];
It is equivalent to this:
Shape shapes[] = new Shape[n];
What you wanted is this:
Shape** shapes = new Shape*[n];
That way when you access an element in "shapes" it will be of type "Shape*"
The [] operator when used on pointers/arrays such as "shapes[n]" is equivalent to "*(shapes+n)":
[b]
