标题:新手求解一个多重继承的访问问题
取消只看楼主
LBY_CHINA
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-7-9
结帖率:0
已结贴  问题点数:20 回复次数:6 
新手求解一个多重继承的访问问题
#include"iostream.h"
class base{
public:
    int lby;
};

class base1:public base{};
class base2:public base{};
class b12:public base1,public base2{};
class b22:public base1,public base2{};
class kk:public b12,public b22{};
//*******************************************************
main()
{
kk bbb;
}
我想通过对象bbb修改bbb.b22.base2.base.lby=1999;怎样写表达式?
搜索更多相关主题的帖子: include public 表达式 
2013-07-09 12:10
LBY_CHINA
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-7-9
得分:0 
bbb.b22::base2::lby = 1999;
这样的表达式无法通过编译啊!!!!!
2013-07-09 13:34
LBY_CHINA
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-7-9
得分:0 
     我想说的意思的是对于多重公用继承,怎样访问任意深度的基类,当然没有同名的很好访问,但对于上面问题同名情况如何表达,我本意不想用虑基类只产生一个拷贝。就相写出形如:bbb.b22.base2.base.lby=1999或bbb.b12.base2.base.lby=2000这样的访问形式,如不能解决则公有继承的公有成员怎样实现任意访问?
2013-07-09 13:49
LBY_CHINA
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-7-9
得分:0 
对不起我用VC6。0调试通不过我没有VC2012
2013-07-09 13:52
LBY_CHINA
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-7-9
得分:0 
回复 10楼 love云彩
Compiling...
mm.cpp
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(42) : error C2039: 'base2' : is not a member of 'b22'
        d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(36) : see declaration of 'b22'
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(42) : error C2385: 'kk::lby' is ambiguous
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(42) : warning C4385: could be the 'lby' in base 'base' of base 'base1' of base 'b12' of class 'kk'
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(42) : warning C4385: or the 'lby' in base 'base' of base 'base2' of base 'b12' of class 'kk'
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(42) : warning C4385: or the 'lby' in base 'base' of base 'base1' of base 'b22' of class 'kk'
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(42) : warning C4385: or the 'lby' in base 'base' of base 'base2' of base 'b22' of class 'kk'
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(44) : error C2039: 'base2' : is not a member of 'b22'
        d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(36) : see declaration of 'b22'
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(44) : error C2385: 'kk::lby' is ambiguous
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(44) : warning C4385: could be the 'lby' in base 'base' of base 'base1' of base 'b12' of class 'kk'
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(44) : warning C4385: or the 'lby' in base 'base' of base 'base2' of base 'b12' of class 'kk'
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(44) : warning C4385: or the 'lby' in base 'base' of base 'base1' of base 'b22' of class 'kk'
d:\program files\microsoft visual studio\myprojects\mb\mm.cpp(44) : warning C4385: or the 'lby' in base 'base' of base 'base2' of base 'b22' of class 'kk'
执行 cl.exe 时出错.

mm.obj - 1 error(s), 0 warning(s)
我的不行,不知为何??
2013-07-09 15:28
LBY_CHINA
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-7-9
得分:0 
回复 12楼 love云彩
上面就是复制的结果,并且如果删去
// bbb.b22::base2::lby = 1999;
    // 或
    //bbb.b22::base2::base::lby = 1999;
这两句就能编译通过,难道是我的编译器有问题。
2013-07-09 15:37
LBY_CHINA
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-7-9
得分:0 
回复 12楼 love云彩
对了,对于二重深度的访问,形如。A.BB1::F(),A.BB2::F()这样的表达式是没有问题的。但是再写下去三重深度
A.BB1::CCC1::F()这样类型的表达式的形式就不行了。
2013-07-09 15:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-416963-1-1.html




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

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