How do I create/initialize a large class static (const?) array?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I need to create a class static (const?) array and then initialize it once
when the first instance of the class is declared after which it should never
be modified, only read.  This array is too large to use the array {...}
initializer syntax.  I need to initialize the array with an algorithm.

The following obviously does not work, but I'm not sure how to do it. (It is
very easy in Java!)

#include <stdint.h>

class TestStatic {
	static const uint32_t SIZE = 1024;
	static uint32_t A[SIZE];
	static bool initialized; //initially false

	public:
	TestStatic() {
		if (!initialized) {
			for (uint32_t i=0; i<SIZE; i++) {
				A[i] = i;
				//actual algorithm is more complex
			}
		}
	}
};

void main() {
	TestStatic TS; //creates "undefined reference" errors
}

Thanks in advance,

Lee.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux