头文件:
#define MAX 2
class A
{
A();
public:
int num;
};
class B
{
static A * m[MAX];
static void p();
};源文件:
#include "test.h"
#include "iostream"
using namespace std;
A::A()
{
num=1;
}
void B::p()
{
for (int i=0;i<MAX;i++)
{
cout<<m[i]->num<<endl;
}
}
void main()
{
for(int i=0;i<MAX;i++)
{
A * B::m[i]=NULL;
}
B::p();
}
报错:
1>正在编译...
1>test.cpp
1>f:\h.323\test\statictest\statictest\test.cpp(19) : error C2057: 应输入常量表达式
1>f:\h.323\test\statictest\statictest\test.cpp(19) : error C2466: 不能分配常量大小为 0 的数组
1>f:\h.323\test\statictest\statictest\test.cpp(19) : error C2655: “B::m”: 当前范围内的定义或重新声明非法
1>        f:\h.323\test\statictest\statictest\test.h(10) : 参见“B::m”的声明
1>f:\h.323\test\statictest\statictest\test.cpp(19) : error C2086: “A *B::m[2]”: 重定义
1>        f:\h.323\test\statictest\statictest\test.h(10) : 参见“m”的声明
1>f:\h.323\test\statictest\statictest\test.cpp(19) : error C2440: “初始化”: 无法从“int”转换为“A *[]”
1>        没有转换为数组类型,但有转换为数组的引用或指针
1>f:\h.323\test\statictest\statictest\test.cpp(21) : error C2248: “B::p”: 无法访问 private 成员(在“B”类中声明)
1>        f:\h.323\test\statictest\statictest\test.h(11) : 参见“B::p”的声明
1>        f:\h.323\test\statictest\statictest\test.h(9) : 参见“B”的声明
1>生成日志保存在“file://f:\h.323\test\statictest\statictest\Debug\BuildLog.htm”
1>statictest - 6 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
求解!!!!!!!!!!!!!!!!!!!!