const int BUF_SIZE = 512;
	static const int BUF_SIZE = 512;	//Static is needed when defining at class level

#define may also be used, e.g.:-

	#define	VIDEO_LOG_PATH "C:\\Video_Log_Archive"
const objects are local to a file by default

Unlike other variables, const variables declared at global scope are local to the file in which the object is created. To use across different files:-
In file 1:

	extern const int BUF_SIZE = 512;	//Declaration must include extern as well as value

In file 2, 3, 4…:

	extern const int BUF_SIZE;		//There is no value which signifies that the cost is external

However, the reason for this is that a const can be used in a header file in the same way as #define – if doing that then there is no need to use extern as every file that needs the const value will be including the header file which will have the const with its scope always being local to that file rather than global.

Creating a constant lookup table in a class

	static array<Byte> ^encryptionKey = {0x45, 0x12, 0x67};

Using const is not permitted (if you have static const array… you get a warning saying const not supported but it will still compile).

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.


Your email address will not be published. Required fields are marked *