头文件:
#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 个 ==========
求解!!!!!!!!!!!!!!!!!!!!
#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 个 ==========
求解!!!!!!!!!!!!!!!!!!!!
解决方案 »
- cannot open file '.\Debug\StdAfx.sbr'
- 求助:3次b样条函数
- 请问 vc2005如可以生成makefile么
- ★★★强烈谴责CSDN回帖页面左边的长幅广告!★★★
- raw socket为什么只能抓到incoming?2贴200分求助!<1>
- 程序非正常退出问题
- 我想通过一段代码注册SQL SEVER数据源,IP=192.168.0.1;ID=sa;PWD=acc;DB=db2000?
- 永远不学mfc的8080问大家一个问题,为什么大家都喜欢MFC而不且API编程呢,API让我爱的发疯!!!!!!
- 把c语言写的exe程序,改写为dll程序该如何做?
- 一个关于线程数据的问题
- w7系统的窗口上的图案//怎么在对话框外面也能显示呢?
- 部门领导,让我接私活
A* B::m [MAX];
void main()
//.....or(int i=0;i<MAX;i++)
{
B::m[i]=NULL;
}
B::p();--->因为前面赋值为NULL,会抛异常。
补充
class B
{
public:
static A * m[MAX];
static void p();
};