可以在.h文件中通过const声明全局的常量,范例如下:
#ifndef TEST_H
#define TEST_H
namespace test{
//整形
const int t = 5;
//数组
const int a[5][3] ={ {1,2,3}, {4,5,1}, {4,5,1}, {4,5,1}, {4,5,1}};
//结构体
struct testIn{
int m;
int n;
};
struct testOut{
int m;
struct testIn n;
};
const struct testOut b ={5,{3,4}};
}
#endif
#ifndef TEST_H
#define TEST_H
namespace test{
//整形
const int t = 5;
//数组
const int a[5][3] ={ {1,2,3}, {4,5,1}, {4,5,1}, {4,5,1}, {4,5,1}};
//结构体
struct testIn{
int m;
int n;
};
struct testOut{
int m;
struct testIn n;
};
const struct testOut b ={5,{3,4}};
}
#endif