'initializing' :cannot convert from 'class A *' to 'class B *'int main(){A aa;B *pb=&aa;pb->g();return 0;}#includeclass A{public:void virtual g(){cout
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 07:32:26
xQMO@+P h=ShRnAIn-
b1zLBb
x/X8x&̾7SbD(кEQjrMڬYN,n
p3ʡ\
Rbr&>TٜbոcQ8VZS%\`ŦI$wq/aK4bO@WDTd;
%bjAƉ#nKfj_\hxuߣE!l/>AU^F(^'.>/+/GM`셷OA;j>dC+A2)Џ[;,
GbU7Z'
'initializing' :cannot convert from 'class A *' to 'class B *'int main(){A aa;B *pb=&aa;pb->g();return 0;}#includeclass A{public:void virtual g(){cout
'initializing' :cannot convert from 'class A *' to 'class B *'
int main()
{
A aa;
B *pb=&aa;
pb->g();
return 0;
}
#include
class A
{
public:
void virtual g(){cout
'initializing' :cannot convert from 'class A *' to 'class B *'int main(){A aa;B *pb=&aa;pb->g();return 0;}#includeclass A{public:void virtual g(){cout
A是B的父类,所以B的指针可以赋值给A的指针,但是A的指针不能赋值给B的指针,你这个正好搞反了,可以这样:
B bb;
A *pa = &bb;
pa->g(); // 相当于bb.g();