错误:从'bottom**'到'lefta**'的转换无效
error: invalid conversion from 'bottom**' to 'lefta**'
我正在尝试编译并运行这个程序。显然,它不起作用!我的问题是,为什么从bottom**到lefta**的转换是无效的,而bottom*可以转换成lefta*?
#include<iostream>
using namespace std;
class top
{
private:
int a;
public:
top(int b):a(b){}
virtual void output(){cout<<a<<endl;}
};
class lefta:virtual public top
{
private:
int b;
public:
lefta(int c,int d):top(c),b(d){}
void output(){cout<<b<<endl;}
};
class righta:virtual public top
{
private:
int c;
public:
righta(int c,int d):top(c),c(d){}
void output(){cout<<c<<endl;}
};
class bottom:public lefta,public righta
{
private:
int d;
public:
bottom(int e,int f,int g,int h):top(e),lefta(e,f),righta(e,g),d(h){}
void output(){cout<<d<<endl;}
};
int main()
{
bottom* bo=new bottom(1,2,3,4);
// lefta* le=bo;
// le->output();
bottom** p_bo=&bo;//here
lefta** p_le=p_bo;//here
(*p_le)->output();
return 0;
}
class leftb : public lefta { /* blah */ };
bottom* bo = new bottom(1,2,3,4);
bottom** p_bo = &bo;
lefta** p_le = p_bo;// let's pretend it works
// now p_le points to the variable bo, which is of type bottom*
// so *p_le is a reference to the variable bo
*p_le = new leftb(1,2); // wait, did we just assign a leftb* to a bottom*?
// (and yeah, I'm leaking memory. Sue me)
// bo now points to a leftb, but it is a bottom*
// oops, we just broke the type system
相关文章:
- C++ PTHREADS - 无效转换无效*(*)()到无效*(*)(无效*)
- is_same和variadic模板编译时错误无效转换
- 如何将常量无效*转换为istream?
- 无效* 转换获得意外输出
- 无法确定为什么函数调用中从 char* 到 char 的无效转换
- 在这个简单函数中从'char'到'const char*'的无效转换
- C++从 'const char*' 到 'char*' Arduino Uno 的无效转换
- 如何修复C++中的"错误:从'int'到'const char*'[-fallowive]的无效转换?
- C 错误:从(基类模板)到子类的无效转换
- 如何将常量无效*转换为无符号字符*
- 函数模板中的无效转换错误,返回值取决于其泛型类型
- 常量正确性编译错误到模板函数中的无效转换错误
- 从"char"到"const char*"的无效转换[-fpermissive](idk why)
- 从“ void*”到“ pthread_t*”的无效转换
- 当函数调用时,试图阻止数组更改时发生无效转换错误
- 使用基类中定义的函数返回指向派生类实例的指针时发生无效转换错误
- C++从字符到常量字符*的无效转换
- ALL_OF从'char'到'const char*'的无效转换 [-允许]
- C和C++上的无效转换错误
- C++ 在模板专用化中从 strcmp() 中的 'char' 到 'const char*' 的无效转换