| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1666 人关注过本帖
标题:急:请教一个有关常数据成员的问题
取消只看楼主 加入收藏
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
 问题点数:0 回复次数:4 
急:请教一个有关常数据成员的问题
小弟是一个初学者,遇到一个问题自己一直不能解决,希望哪位高手能够帮助我。
我定义了一个类
class A
{public:
const int L,M;
A(int, int);
double F[L][M],P[L][M];
………………………………

private:
double Q[L][M];
…………………………
};

A::A(int i, int j):L(i),M(j){}

同时,又有:
class B:private A
{
public:
B(int i, int j):A(i, j){}
………………
public:
double QQ[L][M];
………………
};
这两个类是分别写在两个文件上的。同时,class A和class B分别写在两个头文件中(A.h&B.h),成元函数分别写在两个cpp文件中(A.cpp&B.cpp),且在开头分别对应#include "A.h", #include "B.h"

然后:
#include "A.cpp"
#include "B.cpp"

main
{
B BM(20,30);
…………………… //定义,调用成元函数和数据
}

但是在我complie 的时候却出现:
error C2327: 'A::L' : member from enclosing class is not a type name, static, or enumerator
……\A.h(17) : error C2065: 'L' : undeclared identifier
……\A.h(17) : error C2057: expected constant expression
……\A.h(17) : warning C4200: nonstandard extension used : zero-sized array in struct/union
……\A.h(17) : error C2327: 'A::M' : member from enclosing class is not a type name, static, or enumerator
……\A.h(17) : error C2065: 'M' : undeclared identifier
……\A.h(17) : error C2057: expected constant expression
……\A.h(17) : error C2229: class 'A' has an illegal zero-sized array
……\A.h(17) : warning C4200: nonstandard extension used : zero-sized array in struct/union

这是怎么回事呢??希望哪位高手能尽快解答!不胜感激!
搜索更多相关主题的帖子: 成员 
2006-04-27 22:24
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 
因为Q[L][M]其实是通过类内的成员函数记算算出来的,所以就没有对其进行初始化。对于L和M,因为它控制数组的大小,同时数组的大小对于不同的情况,我想让他成为一个可变量,让用户输入数值,所以才这么做的。我想让L、M成为形参,然后在定义对象的时候由用户给出。不知道如果想实现这种功能怎么办好呢?
2006-04-28 07:43
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 
多谢了!
2006-04-28 14:34
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 
但是在我改为const int L=…,M=…以后,为什么还出现
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'L' : pure specifier can only be specified for functions
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'M' : pure specifier can only be specified for functions
error C2258: illegal pure syntax, must be '= 0'
2006-04-28 16:17
thunderxu
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-4-27
收藏
得分:0 
赋值了。为什么还会出现这样的结果呢?
2006-04-29 10:45
快速回复:急:请教一个有关常数据成员的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017175 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved