On 13.10.2016 04:49, Ab wrote:
> template <typename elementType = int, int numberOfElements = 5>
> class Array
> {
> //some code
> private:
> // the number of objects currently instantiated
> static size_t arrayCount;
> };
This will give you one `arrayCount` for each used combination of
template parameter values.
> // class Array_include.h
> #include "Array.h" // Array class definition
> using namespace std;
Don't ever do this (in the global namespace) in a header.
> // initializing the template static member arrayCount
> template <typename elementType, int numberOfElements>
> size_t Array<elementType, numberOfElements>::arrayCount = 0;
>
> // ^^^ code block (using GCC compiler) gave me compilation error, and in
> //visual studio it worked without any issues, does anyone know why?
Readers can /guess/ that you've not include a header that defines
`size_t` in the global namespace.
The primary such header is `<stddef.h>`.
But really, why t.f. are you posting without quoting the error message,
and without a complete, minimal example that reproduces the error?
• • •
See the old FAQ's “How do I post a question about code that doesn't work
correctly?” e.g. as mirrored at <url:
http://www.dietmar-kuehl.de/mirror/c++-faq/how-to-post.html#faq-5.8>
Cheers, & hth.,
- Alf