【发布时间】:2020-10-20 02:22:52
【问题描述】:
class A
{
public:
virtual void show()
{
cout << "you are in A";
}
};
class B : public A
{
public:
void show()
{
cout << "you are in B";
}
};
int main()
{
A *a[5];
A **aa[5];
B *b[5];
for (int i = 0; i < 5; i++)
{
a[i] = new A;
aa[i] = &a[i];
aa[i]->show();
b[i] = new B;
aa[i] = &b[i];
aa[i]->show();
}
return 0;
}
错误 : 请求成员'show' in *aa[i] which of type pointer 'A*'
错误:从 'B**' 到 'A**' 的无效转换 [-fpermisive]
【问题讨论】:
-
错误信息是什么?
-
考虑创建一个minimal reproducible example 而不是像
//INSIDE MAIN这样的cmets。帮助我们帮助您。 -
欢迎来到 Stack Overflow。请阅读the help pages,接受SO tour,阅读How to Ask,以及this question checklist。最后请学习如何edit你的问题来改进它,比如向我们展示你得到的错误的完整复制粘贴。实际上是在问一个问题。
-
错误:在 *aa[i] 中请求成员 'show' 类型指针 'A *'
-
错误:从 'B**' 到 'A **' 的无效转换 [-fpermisive]
标签: c++ class pointers dynamic-memory-allocation virtual-functions