I am working in C++ and want to declare an array in the private section of the header file. Now that I am thinking about it, I thought doing so was bad practice? I would think doing this would cause multiple declarations everywhere the header is included? Almost like a mem leak?
Is this correct? I’m not sure what the standard “good” practice would be? Put all array declarations in the .cpp file?
(Assuming non-member, since you didn’t say anything about an encapsulating type. If your use of the term “private” was to be taken literally, then please clarify your question.)
You won’t get a memory leak; you’ll get multiple definition errors.
Put all array definitions in a source file, yes, but you can “forward declare” the array with
externin headers.Not that I’d recommend the use of arrays at all…