注册 登录
编程论坛 C++教室

代码错误在何处,求详解?

w2009w 发布于 2015-06-20 20:22, 673 次点击
#include<iostream>
using namespace std;
struct Base1 {int x;};   //结构体Base1定义
struct Base2 {float y;};   //结构体Base2定义
struct Derived:Base1,Base2{};   //派生类结构体Derived,基类为Base1,Base2,默认继承方式为公有继承
int main(){     //主函数
    Derived *pd=new Derived;
    pd->x=1;pd->y=2.0f;
    void *pv=pd;
    Base2*pd=static_cast<Base2*>(pv);
    cout<<pd->y<<" "<<pb->y<<endl;
    delete pb;
    return 0;
}
5 回复
#2
诸葛欧阳2015-06-20 22:47
两个变量重名吧
#3
w2009w2015-06-21 12:57
给我对每一行进行注释和修改一下嘛!
#4
林月儿2015-06-21 13:08
    Base2*pd2=static_cast<Base2*>(pv);
    cout<<pd->y<<" "<<pd2->y<<endl;
    delete pd;
    delete pd2;
#5
w2009w2015-06-21 13:30
还是搞不清楚
#6
thankyou12015-06-24 17:53
回复 5楼 w2009w
就是两个变量用了同一个名字
1